mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Ruby: Model ActiveSupport extensions to Enumerable
This commit is contained in:
@@ -56,5 +56,70 @@ module ActiveSupport {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extensions to the `Enumerable` module.
|
||||
*/
|
||||
module Enumerable {
|
||||
private class ArrayIndex extends int {
|
||||
ArrayIndex() { this = any(DataFlow::Content::KnownElementContent c).getIndex().getInt() }
|
||||
}
|
||||
|
||||
private class CompactBlankSummary extends SimpleSummarizedCallable {
|
||||
CompactBlankSummary() { this = "compact_blank" }
|
||||
|
||||
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].Element[any]" and
|
||||
output = "ReturnValue.Element[?]" and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
|
||||
private class ExcludingSummary extends SimpleSummarizedCallable {
|
||||
ExcludingSummary() { this = ["excluding", "without"] }
|
||||
|
||||
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].Element[any]" and
|
||||
output = "ReturnValue.Element[?]" and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
|
||||
private class InOrderOfSummary extends SimpleSummarizedCallable {
|
||||
InOrderOfSummary() { this = "in_order_of" }
|
||||
|
||||
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
|
||||
input = "Argument[self].Element[any]" and
|
||||
output = "ReturnValue.Element[?]" and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like `Array#push` but doesn't update the receiver.
|
||||
*/
|
||||
private class IncludingSummary extends SimpleSummarizedCallable {
|
||||
IncludingSummary() { this = "including" }
|
||||
|
||||
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
|
||||
(
|
||||
exists(ArrayIndex i |
|
||||
input = "Argument[self].Element[" + i + "]" and
|
||||
output = "ReturnValue.Element[" + i + "]"
|
||||
)
|
||||
or
|
||||
input = "Argument[self].Element[?]" and
|
||||
output = "ReturnValue.Element[?]"
|
||||
or
|
||||
exists(int i | i in [0 .. (mc.getNumberOfArguments() - 1)] |
|
||||
input = "Argument[" + i + "]" and
|
||||
output = ["ReturnValue.Element[?]"]
|
||||
)
|
||||
) and
|
||||
preservesValue = true
|
||||
}
|
||||
}
|
||||
// TODO: index_by, index_with, pick, pluck (they require Hash dataflow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user