Skip to content

Commit 63c70b9

Browse files
committed
Address review comments
1 parent faf24a4 commit 63c70b9

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

ruby/ql/lib/codeql/ruby/dataflow/FlowSummary.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ module SummaryComponent {
7171
}
7272

7373
/** Gets a summary component that represents a value in a pair at a known key. */
74-
SummaryComponent pairValueKnown(ConstantValue cv) {
75-
result = SC::content(TSingletonContent(TKnownPairValueContent(cv)))
74+
SummaryComponent pairValueKnown(ConstantValue key) {
75+
result = SC::content(TSingletonContent(TKnownPairValueContent(key)))
7676
}
7777

7878
/** Gets a summary component that represents the return value of a call. */

ruby/ql/lib/codeql/ruby/frameworks/core/Hash.qll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ module Hash {
6565
}
6666
}
6767

68+
/**
69+
* `Hash[]` called on an existing hash, e.g.
70+
*
71+
* ```rb
72+
* h = {foo: 0, bar: 1, baz: 2}
73+
* Hash[h] # => {:foo=>0, :bar=>1, :baz=>2}
74+
* ```
75+
*
76+
* or on a 2-element array, e.g.
77+
*
78+
* ```rb
79+
* Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1}
80+
* ```
81+
*/
6882
private class HashNewSummary extends SummarizedCallable {
6983
HashNewSummary() { this = "Hash[]" }
7084

@@ -87,11 +101,18 @@ module Hash {
87101
}
88102
}
89103

90-
private class HashNewSummary2 extends SummarizedCallable {
104+
/**
105+
* `Hash[]` called on an even number of arguments, e.g.
106+
*
107+
* ```rb
108+
* Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1}
109+
* ```
110+
*/
111+
private class HashNewSuccessivePairsSummary extends SummarizedCallable {
91112
private int i;
92113
private ConstantValue cv;
93114

94-
HashNewSummary2() {
115+
HashNewSuccessivePairsSummary() {
95116
this = "Hash[" + i + ", " + cv.serialize() + "]" and
96117
i % 2 = 1 and
97118
exists(ElementReference er |

0 commit comments

Comments
 (0)