Skip to content

Commit e6884cf

Browse files
authored
Merge pull request #18959 from erik-krogh/faster-routing
JS: ensure the result from getPathFromFork is unique (to avoid a blowup)
2 parents 73c0a93 + b70643b commit e6884cf

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

javascript/ql/lib/semmle/javascript/Routing.qll

+18-10
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,35 @@ module Routing {
188188
)
189189
}
190190

191-
/**
192-
* Gets the path prefix needed to reach this node from the given ancestor, that is, the concatenation
193-
* of all relative paths between this node and the ancestor.
194-
*
195-
* To restrict the size of the predicate, this is only available for the ancestors that are "fork" nodes,
196-
* that is, a node that has siblings (i.e. multiple children).
197-
*/
198-
private string getPathFromFork(Node fork) {
191+
private string getPathFromForkInternal(Node fork) {
199192
this.isFork() and
200193
this = fork and
201194
result = ""
202195
or
203196
exists(Node parent | parent = this.getParent() |
204197
not exists(parent.getRelativePath()) and
205-
result = parent.getPathFromFork(fork)
198+
result = parent.getPathFromForkInternal(fork)
206199
or
207-
result = parent.getPathFromFork(fork) + parent.getRelativePath() and
200+
result = parent.getPathFromForkInternal(fork) + parent.getRelativePath() and
208201
result.length() < 100
209202
)
210203
}
211204

205+
/**
206+
* Gets the path prefix needed to reach this node from the given ancestor, that is, the concatenation
207+
* of all relative paths between this node and the ancestor.
208+
*
209+
* To restrict the size of the predicate, this is only available for the ancestors that are "fork" nodes,
210+
* that is, a node that has siblings (i.e. multiple children).
211+
* And only a single (shortest) path is returned, even if there are multiple paths
212+
* leading to this node.
213+
*/
214+
pragma[nomagic]
215+
private string getPathFromFork(Node fork) {
216+
result =
217+
min(string res | res = this.getPathFromForkInternal(fork) | res order by res.length(), res)
218+
}
219+
212220
/**
213221
* Gets an HTTP method required to reach this node from the given ancestor, or `*` if any method
214222
* can be used.

0 commit comments

Comments
 (0)