From 46a6c17c1d58f72ab0f1934669670ed179f06c72 Mon Sep 17 00:00:00 2001 From: aleclarson Date: Sat, 11 Nov 2017 09:37:26 -0500 Subject: [PATCH] Avoid matching sourceMappingURL inside a template string NOTE: Multi-line template strings are not protected against. This commit also updates the comment above the 'sourceMappingURL' regular expression that would cause a false positive when this library parses itself (which can happen when two packages depend on this library). --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8d8674c..2d08f1e 100644 --- a/index.js +++ b/index.js @@ -10,9 +10,8 @@ Object.defineProperty(exports, 'commentRegex', { Object.defineProperty(exports, 'mapFileCommentRegex', { get: function getMapFileCommentRegex () { - //Example (Extra space between slashes added to solve Safari bug. Exclude space in production): - // / /# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */ - return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg; + // Matches sourceMappingURL in either // or /* comment styles. + return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"`]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg; } });