Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Enabled Regular Expression Unicode Sets #18055

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions javascript/extractor/src/com/semmle/jcorn/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ private Token readRegexp() {
String validFlags = "gim";
if (this.options.ecmaVersion() >= 6) validFlags = "gimuy";
if (this.options.ecmaVersion() >= 9) validFlags = "gimsuy";
if (this.options.ecmaVersion() >= 12) validFlags = "gimsuyv";
if (!mods.matches("^[" + validFlags + "]*$"))
this.raise(start, "Invalid regular expression flag");
if (mods.indexOf('u') >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static enum ECMAVersion {
ECMA2017(2017, 8),
ECMA2018(2018, 9),
ECMA2019(2019, 10),
ECMA2020(2020, 11);
ECMA2020(2020, 11),
ECMA2021(2021, 12);

private final int version;
public final int legacyVersion;
Expand Down Expand Up @@ -232,7 +233,7 @@ public Set<String> getPredefinedGlobals() {
private VirtualSourceRoot virtualSourceRoot;

public ExtractorConfig(boolean experimental) {
this.ecmaVersion = experimental ? ECMAVersion.ECMA2020 : ECMAVersion.ECMA2019;
this.ecmaVersion = experimental ? ECMAVersion.ECMA2021 : ECMAVersion.ECMA2019;
this.platform = Platform.AUTO;
this.jsx = true;
this.sourceType = SourceType.AUTO;
Expand Down
3 changes: 3 additions & 0 deletions javascript/ql/lib/semmle/javascript/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ class RegExpLiteral extends @regexp_literal, Literal, RegExpParent {
/** Holds if this regular expression has an `s` flag. */
predicate isDotAll() { RegExp::isDotAll(this.getFlags()) }

/** Holds if this regular expression has an `v` flag. */
predicate isUnicodeSets() { RegExp::isUnicodeSets(this.getFlags()) }

override string getAPrimaryQlClass() { result = "RegExpLiteral" }
}

Expand Down
4 changes: 4 additions & 0 deletions javascript/ql/lib/semmle/javascript/Regexp.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,10 @@ module RegExp {
bindingset[flags]
predicate isDotAll(string flags) { flags.matches("%s%") }

/** Holds if `flags` includes the `v` flag. */
bindingset[flags]
predicate isUnicodeSets(string flags) { flags.matches("%v%") }

/** Holds if `flags` includes the `m` flag or is the unknown flag `?`. */
bindingset[flags]
predicate maybeMultiline(string flags) { flags = unknownFlag() or isMultiline(flags) }
Expand Down