mirror of
https://github.com/github/codeql.git
synced 2026-04-22 23:35:14 +02:00
Python: only expose lengths of quote and prefix
This commit is contained in:
@@ -155,11 +155,15 @@ class StringPart extends StringPart_, AstNode {
|
||||
|
||||
override Location getLocation() { result = StringPart_.super.getLocation() }
|
||||
|
||||
/** Holds if the content of string `StringPart` is surrounded by `prefix` and `quote`. */
|
||||
predicate context(string prefix, string quote) {
|
||||
/**
|
||||
* Holds if the content of string `StringPart` is surrounded by
|
||||
* a prefix (including a quote) of length `prefixLength` and
|
||||
* a quote of length `quoteLength`.
|
||||
*/
|
||||
predicate contextSize(int prefixLength, int quoteLength) {
|
||||
exists(int occurrenceOffset |
|
||||
quote = this.getText().regexpFind("\"{3}|\"{1}|'{3}|'{1}", 0, occurrenceOffset) and
|
||||
prefix = this.getText().prefix(occurrenceOffset + quote.length())
|
||||
quoteLength = this.getText().regexpFind("\"{3}|\"{1}|'{3}|'{1}", 0, occurrenceOffset).length() and
|
||||
prefixLength = occurrenceOffset + quoteLength
|
||||
)
|
||||
}
|
||||
|
||||
@@ -168,8 +172,8 @@ class StringPart extends StringPart_, AstNode {
|
||||
* See `context` for obtaining the prefix and the quote.
|
||||
*/
|
||||
int getContentLength() {
|
||||
exists(string prefix, string quote | this.context(prefix, quote) |
|
||||
result = this.getText().length() - prefix.length() - quote.length()
|
||||
exists(int prefixLength, int quoteLength | this.contextSize(prefixLength, quoteLength) |
|
||||
result = this.getText().length() - prefixLength - quoteLength
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ module Impl implements RegexTreeViewSig {
|
||||
index > 0 and
|
||||
exists(int previousOffset | previousOffset = this.getPartOffset(index - 1) |
|
||||
result =
|
||||
previousOffset + re.(StrConst).getImplicitlyConcatenatedPart(index - 1).getContentlength()
|
||||
previousOffset + re.(StrConst).getImplicitlyConcatenatedPart(index - 1).getContentLength()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ module Impl implements RegexTreeViewSig {
|
||||
StringPart getPart(int localOffset) {
|
||||
exists(int index, int prefixLength | index = max(int i | this.getPartOffset(i) < start) |
|
||||
result = re.(StrConst).getImplicitlyConcatenatedPart(index) and
|
||||
exists(string prefix | result.context(prefix, _) | prefixLength = prefix.length()) and
|
||||
result.contextSize(prefixLength, _) and
|
||||
// Example:
|
||||
// re.compile('...' r"""...this..""")
|
||||
// - `start` is the offset from `(` to `this` as counted after concatenating all parts.
|
||||
|
||||
Reference in New Issue
Block a user