Skip to content

Commit cd34686

Browse files
committed
Ruby: Document flow summary for Hash#extract!
1 parent ca7b48c commit cd34686

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActiveSupport.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,25 @@ module ActiveSupport {
118118
result = DataFlow::Content::getKnownElementIndex(mc.getArgument(i)).serialize()
119119
}
120120

121+
/**
122+
*A flow summary for `Hash#extract!`. This method removes the key/value pairs
123+
*matching the given keys from the receiver and returns them (as a Hash).
124+
*
125+
*Example:
126+
*
127+
*```rb
128+
* hash = { a: 1, b: 2, c: 3, d: 4 }
129+
* hash.extract!(:a, :b) # => {:a=>1, :b=>2}
130+
* hash # => {:c=>3, :d=>4}
131+
*```
132+
*
133+
* There is value flow from elements corresponding to keys in the
134+
* arguments (`:a` and `:b` in the example) to elements in
135+
* the return value.
136+
* There is also value flow from any element corresponding to a key _not_
137+
* mentioned in the arguments to an element in `self`, including elements
138+
* at unknown keys.
139+
*/
121140
private class ExtractSummary extends SummarizedCallable {
122141
MethodCall mc;
123142

@@ -137,6 +156,9 @@ module ActiveSupport {
137156
output = "ReturnValue.Element[" + s + "!]"
138157
)
139158
or
159+
// Argument[self].WithoutElement[:a!, :b!].WithElement[any] means
160+
// "an element of self whose key is not :a or :b, including elements
161+
// with unknown keys"
140162
input =
141163
"Argument[self]" +
142164
concat(int i, string s |

0 commit comments

Comments
 (0)