Skip to content

Commit

Permalink
Merge pull request #324 from markdalgleish/prefix-hashes-with-undersc…
Browse files Browse the repository at this point in the history
…ores-based-on-css-spec

Prefix hashes with underscores based on CSS spec
  • Loading branch information
sokra authored Sep 2, 2016
2 parents 278d6cc + da27c07 commit 5a9c1d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/getLocalIdent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ module.exports = function getLocalIdent(loaderContext, localIdentName, localName
options.content = options.hashPrefix + request + "+" + localName;
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^([^a-zA-Z_])/, "_$1");
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
};
15 changes: 15 additions & 0 deletions test/localTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,19 @@ describe("local", function() {
], {
"bar": "bar--58a3b08b9195a6af0de7431eaf3427c7"
}, "?modules&localIdentName=[local]--[hash]&hashPrefix=x");
testLocal("prefixes leading digit with underscore", ":local(.test) { background: red; }", [
[1, "._1test { background: red; }", ""]
], {
test: "_1test"
}, "?localIdentName=1[local]");
testLocal("prefixes leading hyphen + digit with underscore", ":local(.test) { background: red; }", [
[1, "._-1test { background: red; }", ""]
], {
test: "_-1test"
}, "?localIdentName=-1[local]");
testLocal("prefixes two leading hyphens with underscore", ":local(.test) { background: red; }", [
[1, "._--test { background: red; }", ""]
], {
test: "_--test"
}, "?localIdentName=--[local]");
});

0 comments on commit 5a9c1d1

Please sign in to comment.