Skip to content

Commit d2e1d5b

Browse files
committed
Merge pull request #256 from khoomeister/master
Fixed escapeSpecialCharacters to check for ampersands
2 parents 757301b + 21d9e94 commit d2e1d5b

6 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/formatters/checkstyle-xml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CSSLint.addFormatter({
5050
*
5151
* Rules:
5252
* - single quotes is the escape sequence for double-quotes
53+
* - & is the escape sequence for &
5354
* - &lt; is the escape sequence for <
5455
* - &gt; is the escape sequence for >
5556
*
@@ -60,7 +61,7 @@ CSSLint.addFormatter({
6061
if (!str || str.constructor !== String) {
6162
return "";
6263
}
63-
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
64+
return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
6465
};
6566

6667
if (messages.length > 0) {

src/formatters/csslint-xml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CSSLint.addFormatter({
3636
*
3737
* Rules:
3838
* - single quotes is the escape sequence for double-quotes
39+
* - &amp; is the escape sequence for &
3940
* - &lt; is the escape sequence for <
4041
* - &gt; is the escape sequence for >
4142
*
@@ -46,7 +47,7 @@ CSSLint.addFormatter({
4647
if (!str || str.constructor !== String) {
4748
return "";
4849
}
49-
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50+
return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5051
};
5152

5253
if (messages.length > 0) {

src/formatters/lint-xml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CSSLint.addFormatter({
3636
*
3737
* Rules:
3838
* - single quotes is the escape sequence for double-quotes
39+
* - &amp; is the escape sequence for &
3940
* - &lt; is the escape sequence for <
4041
* - &gt; is the escape sequence for >
4142
*
@@ -46,7 +47,7 @@ CSSLint.addFormatter({
4647
if (!str || str.constructor !== String) {
4748
return "";
4849
}
49-
return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
50+
return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5051
};
5152

5253
if (messages.length > 0) {

tests/formatters/checkstyle-xml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
},
2828

2929
"Formatter should escape special characters": function() {
30-
var specialCharsSting = 'sneaky, "sneaky", <sneaky>',
30+
var specialCharsSting = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
3131
result = { messages: [
3232
{ type: "warning", line: 1, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] },
3333
{ type: "error", line: 2, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] }
3434
], stats: [] },
3535
file = "<file name=\"FILE\">",
36-
error1 = "<error line=\"1\" column=\"1\" severity=\"warning\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;\" source=\"\"/>",
37-
error2 = "<error line=\"2\" column=\"1\" severity=\"error\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;\" source=\"\"/>",
36+
error1 = "<error line=\"1\" column=\"1\" severity=\"warning\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\" source=\"\"/>",
37+
error2 = "<error line=\"2\" column=\"1\" severity=\"error\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\" source=\"\"/>",
3838
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>" + file + error1 + error2 + "</file></checkstyle>",
3939
actual = CSSLint.format(result, "FILE", "checkstyle-xml");
4040
Assert.areEqual(expected, actual);

tests/formatters/csslint-xml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
},
2727

2828
"Formatter should escape double quotes": function() {
29-
var doubleQuotedEvidence = 'sneaky, "sneaky"',
29+
var doubleQuotedEvidence = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
3030
result = { messages: [
3131
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] },
3232
{ type: "error", line: 2, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] }
3333
], stats: [] },
3434
file = "<file name=\"FILE\">",
35-
error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
36-
error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
35+
error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
36+
error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
3737
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>" + file + error1 + error2 + "</file></csslint>",
3838
actual = CSSLint.format(result, "FILE", "csslint-xml");
3939
Assert.areEqual(expected, actual);

tests/formatters/lint-xml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
},
2828

2929
"Formatter should escape double quotes": function() {
30-
var doubleQuotedEvidence = 'sneaky, "sneaky"',
30+
var doubleQuotedEvidence = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
3131
result = { messages: [
3232
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] },
3333
{ type: "error", line: 2, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] }
3434
], stats: [] },
3535
file = "<file name=\"FILE\">",
36-
error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
37-
error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
36+
error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
37+
error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
3838
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>" + file + error1 + error2 + "</file></lint>",
3939
actual = CSSLint.format(result, "FILE", "lint-xml");
4040
Assert.areEqual(expected, actual);

0 commit comments

Comments
 (0)