Skip to content

Commit b4207c7

Browse files
committed
Alphanumeric attributes
* adds support for alphanumeric attributes * updates parser test case * fixes loader test case
1 parent 2a4388a commit b4207c7

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
*.sw*

lib/attributesParser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ var parser = new Parser({
2727
inside: {
2828
"\\s+": true, // eat up whitespace
2929
">": "outside", // end of attributes
30-
"(([a-zA-Z\\-]+)\\s*=\\s*\")([^\"]*)\"": processMatch,
31-
"(([a-zA-Z\\-]+)\\s*=\\s*\')([^\']*)\'": processMatch,
32-
"(([a-zA-Z\\-]+)\\s*=\\s*)([^\\s>]+)": processMatch
30+
"(([0-9a-zA-Z\\-]+)\\s*=\\s*\")([^\"]*)\"": processMatch,
31+
"(([0-9a-zA-Z\\-]+)\\s*=\\s*\')([^\']*)\'": processMatch,
32+
"(([0-9a-zA-Z\\-]+)\\s*=\\s*)([^\\s>]+)": processMatch
3333
}
3434
});
3535

@@ -40,4 +40,4 @@ module.exports = function parse(html, isRelevantTagAttr) {
4040
results: [],
4141
isRelevantTagAttr: isRelevantTagAttr
4242
}).results;
43-
};
43+
};

test/loaderTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("loader", function() {
3838
loader.call({
3939
minimize: true
4040
}, '<!-- comment --><h3>#{number} {customer}</h3>\n<p> {title} </p>\n\t <!-- comment --> <img src="image.png" />').should.be.eql(
41-
'module.exports = "<h3>#{number} {customer}</h3><p>{title}</p><img src=" + require("./image.png") + ">";'
41+
'module.exports = "<h3>#{number} {customer}</h3><p>{title}</p><img src=\\"" + require("./image.png") + "\\">";'
4242
);
4343
});
4444
it("should not translate root-relative urls (without root query)", function() {

test/parserTest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function test(name, html, result) {
77
attrParse(html, function(tag, attr) {
88
if(tag === "img" && attr === "src") return true;
99
if(tag === "link" && attr === "href") return true;
10+
if(tag === "div" && attr === "data-videomp4") return true;
1011
return false;
1112
}).map(function(match) { return match.value }).should.be.eql(result);
1213
});
@@ -28,6 +29,7 @@ describe("parser", function() {
2829
test("tags", '<img src="image.png"><script src="script.js"></script><link type="stylesheet" href="style.css">', ["image.png", "style.css"]);
2930
test("cdata", '<![CDATA[<img src="image.png">]]><img src="image2.png">', ["image2.png"]);
3031
test("doctype", '<!doctype html><img src="image.png">', ["image.png"]);
32+
test("alphanumeric", '<div data-videomp4="video.mp4"></div>', ["video.mp4"]);
3133
});
3234

3335
describe("locations", function() {
@@ -38,4 +40,4 @@ describe("locations", function() {
3840
value: "image.png"
3941
}]);
4042
});
41-
});
43+
});

0 commit comments

Comments
 (0)