From f1bd0cfdf9572737f820b8c012550acf04d45cc4 Mon Sep 17 00:00:00 2001 From: jangarcia Date: Mon, 31 Aug 2015 12:12:33 +0200 Subject: [PATCH 1/6] Allow Prefixes to be empty... ...so we can disable prefixes set with prefix-classes() passing an empty string. --- lib/visitor/evaluator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/visitor/evaluator.js b/lib/visitor/evaluator.js index b4a11826d..b6386e53f 100644 --- a/lib/visitor/evaluator.js +++ b/lib/visitor/evaluator.js @@ -120,7 +120,7 @@ var Evaluator = module.exports = function Evaluator(root, options) { this.imports = options.imports || []; this.globals = options.globals || {}; this.paths = options.paths || []; - this.prefix = options.prefix || ''; + this.prefix = options.prefix; this.filename = options.filename; this.includeCSS = options['include css']; this.resolveURL = functions.url @@ -1403,7 +1403,7 @@ Evaluator.prototype.interpolate = function(node){ return node.name; case 'literal': case 'string': - if (self.prefix && !node.prefixed && !node.val.nodeName) { + if (self.prefix != undefined && !node.prefixed && !node.val.nodeName) { node.val = node.val.replace(/\./g, '.' + self.prefix); node.prefixed = true; } From 580095ec18e80aa75c4532c709ae73ae481409f6 Mon Sep 17 00:00:00 2001 From: Ilya Panasenko Date: Thu, 10 Mar 2016 17:04:48 +0200 Subject: [PATCH 2/6] fix typo in docs/bifs.md --- docs/bifs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/bifs.md b/docs/bifs.md index 620477494..4470e5e02 100644 --- a/docs/bifs.md +++ b/docs/bifs.md @@ -710,7 +710,7 @@ The third argument is optional and overrides the autodetected alpha. // => 'rgba' foo = convert('foo') - tyepof(foo) + typeof(foo) // => 'ident' ## s(fmt, ...) From bba7b258e61b19d7527316b787e4967bc74b039f Mon Sep 17 00:00:00 2001 From: Mikhail Korepanov Date: Fri, 11 Mar 2016 22:49:58 +0300 Subject: [PATCH 3/6] False-positive import loop with empty imported file. Fixes #2142 --- lib/visitor/evaluator.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/visitor/evaluator.js b/lib/visitor/evaluator.js index 858a388e2..b5ddc636c 100644 --- a/lib/visitor/evaluator.js +++ b/lib/visitor/evaluator.js @@ -41,6 +41,15 @@ function importFile(node, file, literal) { } } + // Avoid overflows from importing the same file over again + if (~importStack.indexOf(file)) + throw new Error('import loop has been found'); + + var str = fs.readFileSync(file, 'utf8'); + + // shortcut for empty files + if (!str.trim()) return nodes.null; + // Expose imports node.path = file; node.dirname = dirname(file); @@ -49,21 +58,12 @@ function importFile(node, file, literal) { node.mtime = stat.mtime; this.paths.push(node.dirname); - // Avoid overflows from importing the same file over again - if (~importStack.indexOf(file)) - throw new Error('import loop has been found'); - if (this.options._imports) this.options._imports.push(node.clone()); // Parse the file importStack.push(file); nodes.filename = file; - var str = fs.readFileSync(file, 'utf8'); - - // shortcut for empty files - if (!str.trim()) return nodes.null; - if (literal) { literal = new nodes.Literal(str.replace(/\r\n?/g, '\n')); literal.lineno = literal.column = 1; From ca0fe52522cd290199cf89437d27afe86c56327c Mon Sep 17 00:00:00 2001 From: Mikhail Korepanov Date: Fri, 11 Mar 2016 23:10:50 +0300 Subject: [PATCH 4/6] History up + version bump --- History.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index edcb80a52..e93f8ab9e 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,10 @@ +0.54.1 / 2016-03-11 +=================== + + * Fix: False-positive import loop with empty imported file. + 0.54.0 / 2016-03-05 +=================== * Feature: Added initial reference selector. * Feature: New `embedurl()` bif with optional utf8 uncoding support for SVG. diff --git a/package.json b/package.json index 0b3245ea2..d39978c81 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stylus", "description": "Robust, expressive, and feature-rich CSS superset", - "version": "0.54.0", + "version": "0.54.1", "author": "TJ Holowaychuk ", "keywords": [ "css", From 53db82732242fe2a6174795d501b2ac1ee544f36 Mon Sep 17 00:00:00 2001 From: jangarcia Date: Sun, 19 Feb 2017 14:05:38 +0100 Subject: [PATCH 5/6] fix prefix mixin, add test cases for nested prefix-classes bif --- lib/visitor/evaluator.js | 4 ++-- test/cases/bifs.prefix-classes.css | 24 ++++++++++++++++++++++++ test/cases/bifs.prefix-classes.styl | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/visitor/evaluator.js b/lib/visitor/evaluator.js index 76fae8552..69887a3c6 100644 --- a/lib/visitor/evaluator.js +++ b/lib/visitor/evaluator.js @@ -124,7 +124,7 @@ var Evaluator = module.exports = function Evaluator(root, options) { this.imports = options.imports || []; this.globals = options.globals || {}; this.paths = options.paths || []; - this.prefix = options.prefix; + this.prefix = options.prefix || null; this.filename = options.filename; this.includeCSS = options['include css']; this.resolveURL = functions.url @@ -1417,7 +1417,7 @@ Evaluator.prototype.interpolate = function(node){ return node.name; case 'literal': case 'string': - if (self.prefix != undefined && !node.prefixed && !node.val.nodeName) { + if (self.prefix !== null && !node.prefixed && !node.val.nodeName) { node.val = node.val.replace(/\./g, '.' + self.prefix); node.prefixed = true; } diff --git a/test/cases/bifs.prefix-classes.css b/test/cases/bifs.prefix-classes.css index 65cff4a9c..c1f0b8958 100644 --- a/test/cases/bifs.prefix-classes.css +++ b/test/cases/bifs.prefix-classes.css @@ -7,6 +7,30 @@ .prefix-test2 { width: 1px; } +.outer-prefix-test { + width: 1px; +} +.outer-prefix-test2 { + width: 1px; +} +.outer-prefix-test2 .test3 { + width: 1px; +} +.outer-prefix-test2 .test4 { + width: 1px; +} +.outer-prefix-test2 .test4 .other-prefix-test5 { + width: 1px; +} +.outer-prefix-test2 .test4 .other-prefix-test6 { + width: 1px; +} +.test7 { + width: 1px; +} +.test8 { + width: 1px; +} .bar { width: 10px; } diff --git a/test/cases/bifs.prefix-classes.styl b/test/cases/bifs.prefix-classes.styl index 0ae5a0649..bd5985d90 100644 --- a/test/cases/bifs.prefix-classes.styl +++ b/test/cases/bifs.prefix-classes.styl @@ -11,6 +11,27 @@ foo() .test2 width: 1px ++prefix-classes('outer-prefix-') + .test + width: 1px + .test2 + width: 1px + +prefix-classes('') + .test3 + width: 1px + .test4 + width: 1px + +prefix-classes('other-prefix-') + .test5 + width: 1px + .test6 + width: 1px + +prefix-classes('') + .test7 + width: 1px + .test8 + width: 1px + +foo() width: 10px +prefix-classes('prefix2-') From 166805b5b9d176d0ef3e54d408d7692c483e5909 Mon Sep 17 00:00:00 2001 From: jangarcia Date: Sun, 19 Feb 2017 16:37:20 +0100 Subject: [PATCH 6/6] change prefix-classes bif regex to not match relative and range selectors (#2194) --- lib/visitor/evaluator.js | 2 +- test/cases/bifs.prefix-classes.css | 12 ++++++++++++ test/cases/bifs.prefix-classes.styl | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/visitor/evaluator.js b/lib/visitor/evaluator.js index b5ddc636c..e8f3a9094 100644 --- a/lib/visitor/evaluator.js +++ b/lib/visitor/evaluator.js @@ -1418,7 +1418,7 @@ Evaluator.prototype.interpolate = function(node){ case 'literal': case 'string': if (self.prefix && !node.prefixed && !node.val.nodeName) { - node.val = node.val.replace(/\./g, '.' + self.prefix); + node.val = node.val.replace(/\.(?=[\w-])|^\.$/g, '.' + self.prefix); node.prefixed = true; } return node.val; diff --git a/test/cases/bifs.prefix-classes.css b/test/cases/bifs.prefix-classes.css index 65cff4a9c..91316da66 100644 --- a/test/cases/bifs.prefix-classes.css +++ b/test/cases/bifs.prefix-classes.css @@ -7,6 +7,18 @@ .prefix-test2 { width: 1px; } +.prefix-test { + width: 1px; +} +.prefix-test .prefix-test2 { + width: 1px; +} +.prefix-test .prefix-test3 { + color: #00f; +} +.prefix-test2 .prefix-test4 .prefix-test6 { + color: #008000; +} .bar { width: 10px; } diff --git a/test/cases/bifs.prefix-classes.styl b/test/cases/bifs.prefix-classes.styl index 0ae5a0649..3c19cb05e 100644 --- a/test/cases/bifs.prefix-classes.styl +++ b/test/cases/bifs.prefix-classes.styl @@ -11,6 +11,18 @@ foo() .test2 width: 1px ++prefix-classes('prefix-') + .test + width: 1px + .test2 + width: 1px + ../ .test3 + color: blue + .test4 + .test5 + ^[1..-2] .test6 + color: green + +foo() width: 10px +prefix-classes('prefix2-')