Skip to content

Commit 2907d53

Browse files
committed
Shared: sync AccessPathSyntax.qll and FlowSummaryImpl.qll
1 parent be63cf7 commit 2907d53

File tree

5 files changed

+41
-41
lines changed

5 files changed

+41
-41
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/AccessPathSyntax.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Module for parsing access paths from CSV models, both the identifying access path used
33
* by dynamic languages, and the input/output specifications for summary steps.
44
*
5-
* This file is used by shared data flow library and by the JavaScript libraries
5+
* This file is used by the shared data flow library and by the JavaScript libraries
66
* (which does not use the shared data flow libraries).
77
*/
88

@@ -15,36 +15,36 @@ module AccessPath {
1515
}
1616
}
1717

18+
/** Gets the `n`th token on the access path as a string. */
19+
private string getRawToken(AccessPath path, int n) {
20+
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
21+
// Instead use regexpFind to match valid tokens, and supplement with a final length
22+
// check to ensure all characters were included in a token.
23+
result = path.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
24+
}
25+
1826
/**
1927
* A string that occurs as an access path (either identifying or input/output spec)
2028
* which might be relevant for this database.
2129
*/
2230
class AccessPath extends string instanceof AccessPath::Range {
23-
/** Gets the `n`th token on the access path as a string. */
24-
string getRawToken(int n) {
25-
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
26-
// Instead use regexpFind to match valid tokens, and supplement with a final length
27-
// check to ensure all characters were included in a token.
28-
result = this.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
29-
}
30-
3131
/** Holds if this string is not a syntactically valid access path. */
3232
predicate hasSyntaxError() {
3333
// If the lengths match, all characters must haven been included in a token
3434
// or seen by the `.` lookahead pattern.
3535
this != "" and
36-
not this.length() = sum(int n | | getRawToken(n).length() + 1) - 1
36+
not this.length() = sum(int n | | getRawToken(this, n).length() + 1) - 1
3737
}
3838

3939
/** Gets the `n`th token on the access path (if there are no syntax errors). */
4040
AccessPathToken getToken(int n) {
41-
result = this.getRawToken(n) and
41+
result = getRawToken(this, n) and
4242
not hasSyntaxError()
4343
}
4444

4545
/** Gets the number of tokens on the path (if there are no syntax errors). */
4646
int getNumToken() {
47-
result = count(int n | exists(this.getRawToken(n))) and
47+
result = count(int n | exists(getRawToken(this, n))) and
4848
not hasSyntaxError()
4949
}
5050

@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
5656
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
5757
*/
5858
class AccessPathToken extends string {
59-
AccessPathToken() { this = any(AccessPath path).getRawToken(_) }
59+
AccessPathToken() { this = getRawToken(any(AccessPath path), _) }
6060

6161
private string getPart(int part) {
6262
result = this.regexpCapture("([^\\[]+)(?:\\[([^\\]]*)\\])?", part)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ module Private {
892892

893893
/** Holds if component `c` of specification `spec` cannot be parsed. */
894894
predicate invalidSpecComponent(AccessPath spec, string c) {
895-
c = spec.getRawToken(_) and
895+
c = spec.getToken(_) and
896896
not exists(interpretComponent(c))
897897
}
898898

javascript/ql/lib/semmle/javascript/frameworks/data/internal/AccessPathSyntax.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Module for parsing access paths from CSV models, both the identifying access path used
33
* by dynamic languages, and the input/output specifications for summary steps.
44
*
5-
* This file is used by shared data flow library and by the JavaScript libraries
5+
* This file is used by the shared data flow library and by the JavaScript libraries
66
* (which does not use the shared data flow libraries).
77
*/
88

@@ -15,36 +15,36 @@ module AccessPath {
1515
}
1616
}
1717

18+
/** Gets the `n`th token on the access path as a string. */
19+
private string getRawToken(AccessPath path, int n) {
20+
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
21+
// Instead use regexpFind to match valid tokens, and supplement with a final length
22+
// check to ensure all characters were included in a token.
23+
result = path.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
24+
}
25+
1826
/**
1927
* A string that occurs as an access path (either identifying or input/output spec)
2028
* which might be relevant for this database.
2129
*/
2230
class AccessPath extends string instanceof AccessPath::Range {
23-
/** Gets the `n`th token on the access path as a string. */
24-
string getRawToken(int n) {
25-
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
26-
// Instead use regexpFind to match valid tokens, and supplement with a final length
27-
// check to ensure all characters were included in a token.
28-
result = this.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
29-
}
30-
3131
/** Holds if this string is not a syntactically valid access path. */
3232
predicate hasSyntaxError() {
3333
// If the lengths match, all characters must haven been included in a token
3434
// or seen by the `.` lookahead pattern.
3535
this != "" and
36-
not this.length() = sum(int n | | getRawToken(n).length() + 1) - 1
36+
not this.length() = sum(int n | | getRawToken(this, n).length() + 1) - 1
3737
}
3838

3939
/** Gets the `n`th token on the access path (if there are no syntax errors). */
4040
AccessPathToken getToken(int n) {
41-
result = this.getRawToken(n) and
41+
result = getRawToken(this, n) and
4242
not hasSyntaxError()
4343
}
4444

4545
/** Gets the number of tokens on the path (if there are no syntax errors). */
4646
int getNumToken() {
47-
result = count(int n | exists(this.getRawToken(n))) and
47+
result = count(int n | exists(getRawToken(this, n))) and
4848
not hasSyntaxError()
4949
}
5050

@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
5656
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
5757
*/
5858
class AccessPathToken extends string {
59-
AccessPathToken() { this = any(AccessPath path).getRawToken(_) }
59+
AccessPathToken() { this = getRawToken(any(AccessPath path), _) }
6060

6161
private string getPart(int part) {
6262
result = this.regexpCapture("([^\\[]+)(?:\\[([^\\]]*)\\])?", part)

ruby/ql/lib/codeql/ruby/dataflow/internal/AccessPathSyntax.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Module for parsing access paths from CSV models, both the identifying access path used
33
* by dynamic languages, and the input/output specifications for summary steps.
44
*
5-
* This file is used by shared data flow library and by the JavaScript libraries
5+
* This file is used by the shared data flow library and by the JavaScript libraries
66
* (which does not use the shared data flow libraries).
77
*/
88

@@ -15,36 +15,36 @@ module AccessPath {
1515
}
1616
}
1717

18+
/** Gets the `n`th token on the access path as a string. */
19+
private string getRawToken(AccessPath path, int n) {
20+
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
21+
// Instead use regexpFind to match valid tokens, and supplement with a final length
22+
// check to ensure all characters were included in a token.
23+
result = path.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
24+
}
25+
1826
/**
1927
* A string that occurs as an access path (either identifying or input/output spec)
2028
* which might be relevant for this database.
2129
*/
2230
class AccessPath extends string instanceof AccessPath::Range {
23-
/** Gets the `n`th token on the access path as a string. */
24-
string getRawToken(int n) {
25-
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
26-
// Instead use regexpFind to match valid tokens, and supplement with a final length
27-
// check to ensure all characters were included in a token.
28-
result = this.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
29-
}
30-
3131
/** Holds if this string is not a syntactically valid access path. */
3232
predicate hasSyntaxError() {
3333
// If the lengths match, all characters must haven been included in a token
3434
// or seen by the `.` lookahead pattern.
3535
this != "" and
36-
not this.length() = sum(int n | | getRawToken(n).length() + 1) - 1
36+
not this.length() = sum(int n | | getRawToken(this, n).length() + 1) - 1
3737
}
3838

3939
/** Gets the `n`th token on the access path (if there are no syntax errors). */
4040
AccessPathToken getToken(int n) {
41-
result = this.getRawToken(n) and
41+
result = getRawToken(this, n) and
4242
not hasSyntaxError()
4343
}
4444

4545
/** Gets the number of tokens on the path (if there are no syntax errors). */
4646
int getNumToken() {
47-
result = count(int n | exists(this.getRawToken(n))) and
47+
result = count(int n | exists(getRawToken(this, n))) and
4848
not hasSyntaxError()
4949
}
5050

@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
5656
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
5757
*/
5858
class AccessPathToken extends string {
59-
AccessPathToken() { this = any(AccessPath path).getRawToken(_) }
59+
AccessPathToken() { this = getRawToken(any(AccessPath path), _) }
6060

6161
private string getPart(int part) {
6262
result = this.regexpCapture("([^\\[]+)(?:\\[([^\\]]*)\\])?", part)

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ module Private {
892892

893893
/** Holds if component `c` of specification `spec` cannot be parsed. */
894894
predicate invalidSpecComponent(AccessPath spec, string c) {
895-
c = spec.getRawToken(_) and
895+
c = spec.getToken(_) and
896896
not exists(interpretComponent(c))
897897
}
898898

0 commit comments

Comments
 (0)