Skip to content

Commit 766e68a

Browse files
committed
Ruby: Handle multiple gemspecs in endpoints query
1 parent c54743c commit 766e68a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ruby/ql/src/utils/modeleditor/ModelEditor.qll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ private predicate isUninteresting(DataFlow::MethodNode c) {
1414
c.getLocation().getFile() instanceof TestFile
1515
}
1616

17+
private predicate fileStep(Folder folder, File file, int n) {
18+
n = 0 and folder.getAFile() = file
19+
or
20+
exists(int m | fileStep(folder.getAFolder(), file, m) | n = m + 1)
21+
}
22+
23+
private predicate gemFileStep(Gem::GemSpec gem, File file, int n) {
24+
fileStep(any(Folder f | f.getAFile() = gem.(File)), file, n)
25+
}
26+
1727
/**
1828
* A callable method or accessor from either the Ruby Standard Library, a 3rd party library, or from the source.
1929
*/
@@ -29,9 +39,8 @@ class Endpoint extends DataFlow::MethodNode {
2939
*/
3040
bindingset[this]
3141
string getNamespace() {
32-
// Return the name of any gemspec file in the database.
33-
// TODO: make this work for projects with multiple gems (and hence multiple gemspec files)
34-
result = any(Gem::GemSpec g).getName()
42+
// The nearest gemspec to this endpoint
43+
result = min(Gem::GemSpec g, int n | gemFileStep(g, this.getFile(), n) | g order by n).getName()
3544
}
3645

3746
/**

0 commit comments

Comments
 (0)