lydell / source-map-url

[DEPRECATED] Tools for working with sourceMappingURL comments.
MIT License
42 stars 23 forks source link

Regex does not recognize if SourceMappingURL content is within a string #5

Open Koiix opened 4 years ago

Koiix commented 4 years ago

For example, if we had: const sourceMappingURL = require('source-map-url');
const code = 'console.log("//# sourceMappingURL=index.js.map")'; sourceMappingURL.removeFrom(code); There is no SourceMappingURL comment in the piece of code, but the current build would remove the string contents in the code segment.

Koiix commented 4 years ago

A candidate replacement regex might be: /(?:\/\*(?:\s*(?:\/\/)?)?(?:[#@] sourceMappingURL=([^\s'"]*))\s*\*\/|\/\/(?:[#@] sourceMappingURL=([^\s'"]*)))\s*(?=([^"']*"[^'"]*")*[^'"]*$)(?=([^"']*"[^'"]*")*[^'"]*$)/

lydell commented 4 years ago

Hi! I’d recommend not using this package. Here are some alternatives: