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

Skip to content

Commit 12ea81a

Browse files
author
Max Schaefer
committed
JavaScript: Move getAMatchedConstant(RegExpTerm) into the library.
1 parent a5a5deb commit 12ea81a

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

javascript/ql/src/Security/CWE-116/IncompleteSanitization.ql

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,11 @@ string metachar() { result = "'\"\\&<>\n\r\t*|{}[]%$".charAt(_) }
2121

2222
/** Gets a string matched by `e` in a `replace` call. */
2323
string getAMatchedString(Expr e) {
24-
result = getAMatchedConstant(e.(RegExpLiteral).getRoot()).getValue()
24+
result = e.(RegExpLiteral).getRoot().getAMatchedString()
2525
or
2626
result = e.getStringValue()
2727
}
2828

29-
/** Gets a constant matched by `t`. */
30-
RegExpConstant getAMatchedConstant(RegExpTerm t) {
31-
result = t
32-
or
33-
result = getAMatchedConstant(t.(RegExpAlt).getAlternative())
34-
or
35-
result = getAMatchedConstant(t.(RegExpGroup).getAChild())
36-
or
37-
exists(RegExpCharacterClass recc | recc = t and not recc.isInverted() |
38-
result = getAMatchedConstant(recc.getAChild())
39-
)
40-
}
41-
4229
/** Holds if `t` is simple, that is, a union of constants. */
4330
predicate isSimple(RegExpTerm t) {
4431
t instanceof RegExpConstant

javascript/ql/src/semmle/javascript/Regexp.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ class RegExpTerm extends Locatable, @regexpterm {
185185
* into account.
186186
*/
187187
string getConstantValue() { none() }
188+
189+
/**
190+
* Gets a string that is matched by this regular-expression term.
191+
*/
192+
string getAMatchedString() { result = getConstantValue() }
188193
}
189194

190195
/**
@@ -280,6 +285,8 @@ class RegExpAlt extends RegExpTerm, @regexp_alt {
280285
int getNumAlternative() { result = getNumChild() }
281286

282287
override predicate isNullable() { getAlternative().isNullable() }
288+
289+
override string getAMatchedString() { result = getAlternative().getAMatchedString() }
283290
}
284291

285292
/**
@@ -574,6 +581,8 @@ class RegExpGroup extends RegExpTerm, @regexp_group {
574581
override predicate isNullable() { getAChild().isNullable() }
575582

576583
override string getConstantValue() { result = getAChild().getConstantValue() }
584+
585+
override string getAMatchedString() { result = getAChild().getAMatchedString() }
577586
}
578587

579588
/**
@@ -759,6 +768,10 @@ class RegExpCharacterClass extends RegExpTerm, @regexp_char_class {
759768
predicate isInverted() { isInverted(this) }
760769

761770
override predicate isNullable() { none() }
771+
772+
override string getAMatchedString() {
773+
not isInverted() and result = getAChild().getAMatchedString()
774+
}
762775
}
763776

764777
/**

0 commit comments

Comments
 (0)