mirror of
https://github.com/github/codeql.git
synced 2026-02-13 05:31:22 +01:00
Exposed flags to the regex parser
This commit is contained in:
@@ -600,7 +600,7 @@ public class ASTExtractor {
|
||||
SourceMap sourceMap =
|
||||
SourceMap.legacyWithStartPos(
|
||||
SourceMap.fromString(nd.getRaw()).offsetBy(0, offsets), startPos);
|
||||
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false);
|
||||
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false, source.substring(source.lastIndexOf('/'), source.length()));
|
||||
} else if (nd.isStringLiteral()
|
||||
&& !c.isInsideType()
|
||||
&& nd.getRaw().length() < 1000
|
||||
|
||||
@@ -346,8 +346,8 @@ public class RegExpExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
|
||||
Result res = parser.parse(src);
|
||||
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing, String flags) {
|
||||
Result res = parser.parse(src, flags);
|
||||
if (isSpeculativeParsing && res.getErrors().size() > 0) {
|
||||
return;
|
||||
}
|
||||
@@ -364,4 +364,8 @@ public class RegExpExtractor {
|
||||
this.emitLocation(err, lbl);
|
||||
}
|
||||
}
|
||||
|
||||
public void extract(String src, SourceMap sourceMap, Node parent, boolean isSpeculativeParsing) {
|
||||
extract(src, sourceMap, parent, isSpeculativeParsing, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public class RegExpParser {
|
||||
private List<Error> errors;
|
||||
private List<BackReference> backrefs;
|
||||
private int maxbackref;
|
||||
private String flags;
|
||||
|
||||
/** Parse the given string as a regular expression. */
|
||||
public Result parse(String src) {
|
||||
@@ -82,6 +83,11 @@ public class RegExpParser {
|
||||
return new Result(root, errors);
|
||||
}
|
||||
|
||||
public Result parse(String src, String flags) {
|
||||
this.flags = flags;
|
||||
return parse(src);
|
||||
}
|
||||
|
||||
private static String fromCodePoint(int codepoint) {
|
||||
if (Character.isValidCodePoint(codepoint)) return new String(Character.toChars(codepoint));
|
||||
// replacement character
|
||||
|
||||
Reference in New Issue
Block a user