Skip to content

Commit 2c4ba56

Browse files
authored
Merge pull request github#5360 from erik-krogh/regParse
Approved by asgerf
2 parents a2660e5 + 29ae737 commit 2c4ba56

File tree

8 files changed

+369
-353
lines changed

8 files changed

+369
-353
lines changed

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Main {
4343
* A version identifier that should be updated every time the extractor changes in such a way that
4444
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4545
*/
46-
public static final String EXTRACTOR_VERSION = "2021-02-24";
46+
public static final String EXTRACTOR_VERSION = "2021-03-08";
4747

4848
public static final Pattern NEWLINE = Pattern.compile("\n");
4949

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,18 @@ private RegExpTerm parseQuantifierOpt(SourceLocation loc, RegExpTerm atom) {
282282
if (this.match("+")) return this.finishTerm(new Plus(loc, atom, !this.match("?")));
283283
if (this.match("?")) return this.finishTerm(new Opt(loc, atom, !this.match("?")));
284284
if (this.match("{")) {
285-
Double lo = toNumber(this.readDigits(false)), hi;
285+
String matched = "{"; // keeping track of the string matched so far, in case this turns out not to be a quantifier.
286+
String digits = this.readDigits(false);
287+
matched += digits;
288+
Double lo = toNumber(digits), hi;
289+
int prevPos = this.pos;
286290
if (this.match(",")) {
291+
matched += ",";
287292
if (!this.lookahead("}")) {
288293
// atom{lo, hi}
289-
hi = toNumber(this.readDigits(false));
294+
digits = this.readDigits(false);
295+
matched += digits;
296+
hi = toNumber(digits);
290297
} else {
291298
// atom{lo,}
292299
hi = null;
@@ -295,7 +302,11 @@ private RegExpTerm parseQuantifierOpt(SourceLocation loc, RegExpTerm atom) {
295302
// atom{lo}
296303
hi = lo;
297304
}
298-
this.expectRBrace();
305+
if (!this.match("}")) {
306+
// Not a quantifier, just parsing it as a constant.
307+
// E.g. a Regexp such as `/a{|X/`, where there is no matching `}`.
308+
return this.finishTerm(new Sequence(loc, Arrays.asList(atom, new Constant(loc, matched))));
309+
}
299310
return this.finishTerm(new Range(loc, atom, !this.match("?"), lo, hi));
300311
}
301312
return atom;

0 commit comments

Comments
 (0)