From 7be555d066e7b5abfc9a248a9dbc0d23f57077e0 Mon Sep 17 00:00:00 2001 From: benholloway Date: Thu, 21 May 2015 12:48:24 +1000 Subject: [PATCH 1/4] fix base64 encoding of sass url()'s that are not quoted update browserify-nginject to get recent fixes bump patch version --- lib/build/node-sass.js | 103 +++++++++++++++++++++++------------------ npm-shrinkwrap.json | 8 ++-- package.json | 4 +- 3 files changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/build/node-sass.js b/lib/build/node-sass.js index 74a2498..db6b0b2 100644 --- a/lib/build/node-sass.js +++ b/lib/build/node-sass.js @@ -146,54 +146,65 @@ module.exports = function (bannerWidth, libraryPaths) { function reworkPlugin(stylesheet) { // visit each node (selector) in the stylesheet recursively using the official utility method - visit(stylesheet, function (declarations) { - - // each node may have multiple declarations - declarations.forEach(function (declaration) { - - // reverse the original source-map to find the original sass file - var cssStart = declaration.position.start; - var sassStart = sourceMapConsumer.originalPositionFor({ - line: cssStart.line, - column: cssStart.column - }); - if (!sassStart.source) { - throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass + // each node may have multiple declarations + visit(stylesheet, function visitor(declarations) { + declarations + .forEach(eachDeclaration); + }); + + /** + * Process a declaration from the syntax tree. + * @param declaration + */ + function eachDeclaration(declaration) { + var REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g; + + // reverse the original source-map to find the original sass file + var cssStart = declaration.position.start; + var sassStart = sourceMapConsumer.originalPositionFor({ + line : cssStart.line, + column: cssStart.column + }); + if (!sassStart.source) { + throw new Error('failed to decode node-sass source map'); // this can occur with regressions in libsass + } + var sassDir = path.dirname(sassStart.source); + + // allow multiple url() values in the declaration + // split by url statements and process the content + // additional capture groups are needed to match quotations correctly + // escaped quotations are not considered + declaration.value = declaration.value + .split(REGEX) + .map(eachSplitOrGroup) + .join(''); + + /** + * Encode the content portion of url() statements. + * There are 4 capture groups in the split making every 5th unmatched. + * @param {string} token A single split item + * @param i The index of the item in the split + * @returns {string} Every 3 or 5 items is an encoded url everything else is as is + */ + function eachSplitOrGroup(token, i) { + + // we can get groups as undefined under certain match circumstances + var initialised = token || ''; + + // the content of the url() statement is either in group 3 or group 5 + var mod = i % 7; + if ((mod === 3) || (mod === 5)) { + + // remove query string or hash suffix + var uri = initialised.split(/[?#]/g).shift(); + return uri && encodeRelativeURL(sassDir, uri) || initialised; } - var sassDir = path.dirname(sassStart.source); - - // allow multiple url() values in the declaration - // split by url statements and process the content - // additional capture groups are needed to match quotations correctly - // escaped quotations are not considered - declaration.value = declaration.value - .split(/(url\s*\(\s*)(['"]?)((?:(?!\2|\?|#]).)*(?:(?!\2).)*)(\2\s*\))/g) - .map(eachSplitOrGroup) - .join(''); - - /** - * Encode the content portion of url() statements. - * There are 4 capture groups in the split making every 5th unmatched. - * @param {string} token A single split item - * @param i The index of the item in the split - * @returns {string} Every 3 or 5 items is an encoded url everything else is as is - */ - function eachSplitOrGroup(token, i) { - - // the quoted or unquoted content of the url() statement - if (i % 5 === 3) { - - // remove query string or hash suffix - var uri = token.split(/[?#]/g).shift(); - return encodeRelativeURL(sassDir, uri) || token; - } - // everything else, including parentheses and quotation (where present) and media statements - else { - return token; - } + // everything else, including parentheses and quotation (where present) and media statements + else { + return initialised; } - }); - }); + } + } } /** diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 4efd540..0e8959b 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "angularity", - "version": "0.3.0", + "version": "0.3.1", "dependencies": { "alter": { "version": "0.2.0", @@ -1940,9 +1940,9 @@ "resolved": "https://registry.npmjs.org/browserify-incremental-plugin/-/browserify-incremental-plugin-1.0.1.tgz" }, "browserify-nginject": { - "version": "1.3.5", - "from": "browserify-nginject@1.3.5", - "resolved": "https://registry.npmjs.org/browserify-nginject/-/browserify-nginject-1.3.5.tgz" + "version": "1.4.0", + "from": "browserify-nginject@1.4.0", + "resolved": "https://registry.npmjs.org/browserify-nginject/-/browserify-nginject-1.4.0.tgz" }, "browserify-transform-tools": { "version": "1.3.3", diff --git a/package.json b/package.json index 325631b..b8859c5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "angularity", "description": "An opinionated NodeJs build system for ECMAScript 6 AngularJs projects", - "version": "0.3.0", + "version": "0.3.1", "tags": [ "build", "system", @@ -112,7 +112,7 @@ }, "devDependencies": { "angularity-helloworld-es5": "angularity/angularity-helloworld-es5#ci-build-0.2.0-E", - "angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-E", + "angularity-todo-es5": "angularity/angularity-todo-es5#ci-build-0.2.0-F", "autodocs": "^0.6.8", "jasmine-diff-matchers": "~2.0.0", "jasmine-node": "2.0.0-beta4", From 6186db417ddac98ebed7f658bdafa6d7f87f8223 Mon Sep 17 00:00:00 2001 From: benholloway Date: Thu, 21 May 2015 16:44:38 +1000 Subject: [PATCH 2/4] update browserify-nginject to get recent fixes --- npm-shrinkwrap.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0e8959b..4d534ae 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1940,9 +1940,9 @@ "resolved": "https://registry.npmjs.org/browserify-incremental-plugin/-/browserify-incremental-plugin-1.0.1.tgz" }, "browserify-nginject": { - "version": "1.4.0", - "from": "browserify-nginject@1.4.0", - "resolved": "https://registry.npmjs.org/browserify-nginject/-/browserify-nginject-1.4.0.tgz" + "version": "1.4.1", + "from": "browserify-nginject@1.4.1", + "resolved": "https://registry.npmjs.org/browserify-nginject/-/browserify-nginject-1.4.1.tgz" }, "browserify-transform-tools": { "version": "1.3.3", From a9c10239167cb446e25ffd9b159bc273cf253e4e Mon Sep 17 00:00:00 2001 From: benholloway Date: Tue, 26 May 2015 09:43:56 +1000 Subject: [PATCH 3/4] update browserify-incremental-plugin to get recent fixes --- npm-shrinkwrap.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 4d534ae..1b06c96 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1935,9 +1935,9 @@ } }, "browserify-incremental-plugin": { - "version": "1.0.1", - "from": "browserify-incremental-plugin@1.0.1", - "resolved": "https://registry.npmjs.org/browserify-incremental-plugin/-/browserify-incremental-plugin-1.0.1.tgz" + "version": "1.0.2", + "from": "browserify-incremental-plugin@1.0.2", + "resolved": "https://registry.npmjs.org/browserify-incremental-plugin/-/browserify-incremental-plugin-1.0.2.tgz" }, "browserify-nginject": { "version": "1.4.1", From dc718a53be16743f035052a3a4f92d8f8c543d29 Mon Sep 17 00:00:00 2001 From: benholloway Date: Wed, 27 May 2015 12:10:30 +1000 Subject: [PATCH 4/4] more sensible variable name --- lib/build/node-sass.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build/node-sass.js b/lib/build/node-sass.js index db6b0b2..216e950 100644 --- a/lib/build/node-sass.js +++ b/lib/build/node-sass.js @@ -157,7 +157,7 @@ module.exports = function (bannerWidth, libraryPaths) { * @param declaration */ function eachDeclaration(declaration) { - var REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g; + var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g; // reverse the original source-map to find the original sass file var cssStart = declaration.position.start; @@ -175,7 +175,7 @@ module.exports = function (bannerWidth, libraryPaths) { // additional capture groups are needed to match quotations correctly // escaped quotations are not considered declaration.value = declaration.value - .split(REGEX) + .split(URL_STATEMENT_REGEX) .map(eachSplitOrGroup) .join('');