Skip to content

Commit fe28657

Browse files
committed
JS: add test cases with unknown flags for double escaping, works as expected.
1 parent 98fd977 commit fe28657

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

javascript/ql/test/query-tests/Security/CWE-116/DoubleEscaping/DoubleEscaping.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
| tst.js:60:7:60:28 | s.repla ... '%25') | This replacement may double-escape '%' characters from $@. | tst.js:59:7:59:28 | s.repla ... '%26') | here |
77
| tst.js:68:10:70:38 | s.repla ... &") | This replacement may double-escape '&' characters from $@. | tst.js:68:10:69:39 | s.repla ... apos;") | here |
88
| tst.js:79:10:79:66 | s.repla ... &") | This replacement may double-escape '&' characters from $@. | tst.js:79:10:79:43 | s.repla ... epl[c]) | here |
9+
| tst.js:99:10:101:49 | s.repla ... &") | This replacement may double-escape '&' characters from $@. | tst.js:99:10:100:51 | s.repla ... apos;") | here |

javascript/ql/test/query-tests/Security/CWE-116/DoubleEscaping/tst.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,21 @@ function testWithCapturedVar(x) {
9494
function encodeDecodeEncode(s) {
9595
return goodEncode(goodDecode(goodEncode(s)));
9696
}
97+
98+
function badEncode(s) {
99+
return s.replace(new RegExp("\"", "g"), """)
100+
.replace(new RegExp("\'", "g"), "'")
101+
.replace(new RegExp("&", "g"), "&"); // NOT OK
102+
}
103+
104+
function goodEncode(s) {
105+
return s.replace(new RegExp("\"", ""), """)
106+
.replace(new RegExp("\'", ""), "'")
107+
.replace(new RegExp("&", ""), "&"); // OK
108+
}
109+
110+
function goodEncode(s) {
111+
return s.replace(new RegExp("\"", unknownFlags()), """)
112+
.replace(new RegExp("\'", unknownFlags()), "'")
113+
.replace(new RegExp("&", unknownFlags()), "&"); // OK
114+
}

0 commit comments

Comments
 (0)