Skip to content

Commit 6b8a7c2

Browse files
committed
Ruby: Make implicit this receivers explicit
1 parent 3d5c815 commit 6b8a7c2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/Gem.qll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,40 @@ module Gem {
5757
}
5858

5959
/** Gets the name of the gem */
60-
string getName() { result = getSpecProperty("name").getConstantValue().getString() }
60+
string getName() { result = this.getSpecProperty("name").getConstantValue().getString() }
6161

6262
/** Gets a path that is loaded when the gem is required */
6363
private string getARequirePath() {
64-
result = getSpecProperty(["require_paths", "require_path"]).getConstantValue().getString()
64+
result =
65+
this.getSpecProperty(["require_paths", "require_path"]).getConstantValue().getString()
6566
or
66-
not exists(getSpecProperty(["require_paths", "require_path"]).getConstantValue().getString()) and
67+
not exists(
68+
this.getSpecProperty(["require_paths", "require_path"]).getConstantValue().getString()
69+
) and
6770
result = "lib" // the default is "lib"
6871
}
6972

7073
/** Gets a file that could be loaded when the gem is required. */
7174
private File getAPossiblyRequiredFile() {
72-
result = File.super.getParentContainer().getFolder(getARequirePath()).getAChildContainer*()
75+
result =
76+
File.super.getParentContainer().getFolder(this.getARequirePath()).getAChildContainer*()
7377
}
7478

7579
/** Gets a class/module that is exported by this gem. */
7680
private ModuleBase getAPublicModule() {
77-
result.(Toplevel).getLocation().getFile() = getAPossiblyRequiredFile()
81+
result.(Toplevel).getLocation().getFile() = this.getAPossiblyRequiredFile()
7882
or
79-
result = getAPublicModule().getAModule()
83+
result = this.getAPublicModule().getAModule()
8084
or
81-
result = getAPublicModule().getAClass()
85+
result = this.getAPublicModule().getAClass()
8286
or
83-
result = getAPublicModule().getStmt(_).(SingletonClass)
87+
result = this.getAPublicModule().getStmt(_).(SingletonClass)
8488
}
8589

8690
/** Gets a parameter from an exported method, which is an input to this gem. */
8791
DataFlow::ParameterNode getAnInputParameter() {
8892
exists(MethodBase method |
89-
method = getAPublicModule().getAMethod() and
93+
method = this.getAPublicModule().getAMethod() and
9094
result.getParameter() = method.getAParameter()
9195
|
9296
method.isPublic()

ruby/ql/src/queries/meta/internal/TaintMetrics.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private import codeql.ruby.security.UrlRedirectCustomizations
1111
private import codeql.ruby.security.SqlInjectionCustomizations
1212

1313
class RelevantFile extends File {
14-
RelevantFile() { not getRelativePath().regexpMatch(".*/test(case)?s?/.*") }
14+
RelevantFile() { not this.getRelativePath().regexpMatch(".*/test(case)?s?/.*") }
1515
}
1616

1717
RemoteFlowSource relevantTaintSource(string kind) {

ruby/ql/test/library-tests/dataflow/api-graphs/use.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class ApiUseTest extends InlineExpectationsTest {
3838

3939
override predicate hasActualResult(Location location, string element, string tag, string value) {
4040
tag = "use" and // def tags are always optional
41-
exists(DataFlow::Node n | relevantNode(_, n, location, tag) |
41+
exists(DataFlow::Node n | this.relevantNode(_, n, location, tag) |
4242
// Only report the longest path on this line:
4343
value =
4444
max(API::Node a2, Location l2, DataFlow::Node n2 |
45-
relevantNode(a2, n2, l2, tag) and
45+
this.relevantNode(a2, n2, l2, tag) and
4646
l2.getFile() = location.getFile() and
4747
l2.getEndLine() = location.getEndLine()
4848
|
@@ -57,7 +57,7 @@ class ApiUseTest extends InlineExpectationsTest {
5757
// We also permit optional annotations for any other path on the line.
5858
// This is used to test subclass paths, which typically have a shorter canonical path.
5959
override predicate hasOptionalResult(Location location, string element, string tag, string value) {
60-
exists(API::Node a, DataFlow::Node n | relevantNode(a, n, location, tag) |
60+
exists(API::Node a, DataFlow::Node n | this.relevantNode(a, n, location, tag) |
6161
element = n.toString() and
6262
value = getAPath(a, _)
6363
)

0 commit comments

Comments
 (0)