From b90adc4ceee58d665241fbba41f932553ebbce67 Mon Sep 17 00:00:00 2001 From: as Date: Thu, 6 Aug 2020 16:41:17 +0800 Subject: [PATCH] when run into different context,this judge will be wrong. --- lib/url-pattern.js | 2 +- package.json | 2 +- src/url-pattern.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/url-pattern.js b/lib/url-pattern.js index 0d635c2..509a33e 100644 --- a/lib/url-pattern.js +++ b/lib/url-pattern.js @@ -348,7 +348,7 @@ var slice = [].slice; this.names = arg1.names; return; } - this.isRegex = arg1 instanceof RegExp; + this.isRegex = Object.prototype.toString.call(arg1) === '[object RegExp]'; if (!(('string' === typeof arg1) || this.isRegex)) { throw new TypeError('argument must be a regex or a string'); } diff --git a/package.json b/package.json index 7cb6ee7..6986df7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "url-pattern", - "version": "1.0.3", + "version": "1.0.4", "description": "easier than regex string matching patterns for urls and other strings. turn strings into data or data into strings.", "keywords": [ "url", diff --git a/src/url-pattern.coffee b/src/url-pattern.coffee index 10b6904..c060283 100644 --- a/src/url-pattern.coffee +++ b/src/url-pattern.coffee @@ -350,7 +350,7 @@ @names = arg1.names return - @isRegex = arg1 instanceof RegExp + @isRegex = Object.prototype.toString.call(arg1) is '[object RegExp]' unless ('string' is typeof arg1) or @isRegex throw new TypeError 'argument must be a regex or a string'