Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68d23bc

Browse files
committed
JS: Extract surrogate pairs as one constant node
1 parent 6e1c995 commit 68d23bc

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

  • javascript
    • extractor/src/com/semmle/js/parser
    • ql/test/query-tests/RegExp/DuplicateCharacterInCharacterClass

javascript/extractor/src/com/semmle/js/parser/RegExpParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ private RegExpTerm parseCharacterClassAtom() {
489489
if (this.match("b")) return this.finishTerm(new ControlEscape(loc, "\b", 8, "\\b"));
490490
return this.finishTerm(this.parseAtomEscape(loc, true));
491491
}
492-
return this.finishTerm(new Constant(loc, String.valueOf(c)));
492+
String value = String.valueOf(c);
493+
// Extract a surrogate pair as a single constant.
494+
if (Character.isHighSurrogate(c) && Character.isLowSurrogate(peekChar(true))) {
495+
value += this.nextChar();
496+
}
497+
return this.finishTerm(new Constant(loc, value));
493498
}
494499
}

javascript/ql/test/query-tests/RegExp/DuplicateCharacterInCharacterClass/tst.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
/[aaa]/;
99
/[\x0a\x0a]/;
1010
/[\u000a\n]/;
11-
/[\u{ff}]/;
11+
/[\u{ff}]/;
12+
/[\u{12340}-\u{12345}]/u; // OK
13+
new RegExp("[\u{12340}-\u{12345}]", "u"); // OK

0 commit comments

Comments
 (0)