mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Ruby: Avoid computing Location::toString in full
This commit is contained in:
@@ -2,6 +2,15 @@
|
||||
|
||||
import files.FileSystem
|
||||
|
||||
bindingset[loc]
|
||||
pragma[inline_late]
|
||||
private string locationToString(Location loc) {
|
||||
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
|
||||
loc.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
|
||||
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A location as given by a file, a start line, a start column,
|
||||
* an end line, and an end column.
|
||||
@@ -28,12 +37,8 @@ class Location extends @location {
|
||||
int getNumLines() { result = this.getEndLine() - this.getStartLine() + 1 }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() {
|
||||
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
|
||||
this.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
|
||||
result = filepath + "@" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
|
||||
)
|
||||
}
|
||||
pragma[inline]
|
||||
string toString() { result = locationToString(this) }
|
||||
|
||||
/**
|
||||
* Holds if this element is at the specified location.
|
||||
|
||||
@@ -303,6 +303,13 @@ private class CookiesSameSiteProtectionSetting extends Settings::NillableStringl
|
||||
}
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate isPotentialRenderCall(MethodCall renderCall, Location loc, ErbFile erbFile) {
|
||||
renderCall.getMethodName() = "render" and
|
||||
loc = renderCall.getLocation() and
|
||||
RenderCallUtils::getTemplateFile(renderCall) = erbFile
|
||||
}
|
||||
|
||||
// TODO: initialization hooks, e.g. before_configuration, after_initialize...
|
||||
// TODO: initializers
|
||||
/** A synthetic global to represent the value passed to the `locals` argument of a render call for a specific ERB file. */
|
||||
@@ -313,10 +320,11 @@ private class LocalAssignsHashSyntheticGlobal extends SummaryComponent::Syntheti
|
||||
private MethodCall renderCall;
|
||||
|
||||
LocalAssignsHashSyntheticGlobal() {
|
||||
this = "LocalAssignsHashSyntheticGlobal+" + id and
|
||||
id = erbFile.getRelativePath() + "+" + renderCall.getLocation() and
|
||||
renderCall.getMethodName() = "render" and
|
||||
RenderCallUtils::getTemplateFile(renderCall) = erbFile
|
||||
exists(Location loc |
|
||||
this = "LocalAssignsHashSyntheticGlobal+" + id and
|
||||
isPotentialRenderCall(renderCall, loc, erbFile) and
|
||||
id = erbFile.getRelativePath() + "+" + loc
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the `ErbFile` which this locals hash is accessible from. */
|
||||
|
||||
Reference in New Issue
Block a user