From 97f86524b414acf30d52b969d1517a1761bd5ade Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 9 Oct 2015 16:31:49 +0200 Subject: [PATCH] Don't use RegExp to extract sourcemap --- index.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index ee6e811..6d75f94 100644 --- a/index.js +++ b/index.js @@ -11,17 +11,15 @@ var createSourceMapLocatorPreprocessor = function(args, logger, helper) { } function inlineMap(inlineData){ - var data; - var b64Match = inlineData.match(/^data:.+\/(.+);base64,(.*)$/); - if (b64Match !== null && b64Match.length == 3) { + if (/^;base64,/.test(inlineData)) { // base64-encoded JSON string log.debug('base64-encoded source map for', file.originalPath); - var buffer = new Buffer(b64Match[2], 'base64'); + var buffer = new Buffer(inlineData.slice(';base64,'.length), 'base64'); sourceMapData(buffer.toString()); } else { // straight-up URL-encoded JSON string log.debug('raw inline source map for', file.originalPath); - sourceMapData(decodeURIComponent(inlineData.slice('data:application/json'.length))); + sourceMapData(decodeURIComponent(inlineData)); } } @@ -51,7 +49,7 @@ var createSourceMapLocatorPreprocessor = function(args, logger, helper) { if (!mapUrl) { fileMap(file.path + ".map"); } else if (/^data:application\/json/.test(mapUrl)) { - inlineMap(mapUrl); + inlineMap(mapUrl.slice('data:application/json'.length)); } else { fileMap(path.resolve(path.dirname(file.path), mapUrl)); }