Skip to content

Commit b44c2cf

Browse files
committed
Treat hash suffixes as inline expectation notes
Recognize # as a trailing-note delimiter alongside // so learning preserves annotations such as # NOT OK instead of rendering their words as expectation tags. Rewrite the Ruby tests that used repeated # $ delimiters to use unambiguous $ continuations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1adfa307-c48e-43f5-94e3-8286e4a8c083
1 parent 5c5862a commit b44c2cf

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎ruby/ql/test/library-tests/dataflow/array-flow/array_flow.rb‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,24 +371,24 @@ def m41
371371
def m42(i)
372372
a = [0, 1, source(42.1), source(42.2)]
373373
b = a.drop(i)
374-
sink(b[0]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.2
374+
sink(b[0]) # $ hasValueFlow=42.1 hasValueFlow=42.2
375375
b = a.drop(1)
376376
sink(b[0])
377377
sink(b[1]) # $ hasValueFlow=42.1
378-
sink(b[i]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.2
378+
sink(b[i]) # $ hasValueFlow=42.1 hasValueFlow=42.2
379379
a[i] = source(42.3)
380380
b = a.drop(1)
381-
sink(b[1]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.3
381+
sink(b[1]) # $ hasValueFlow=42.1 hasValueFlow=42.3
382382
c = b.drop(100)
383383
sink(c[1]) # $ hasValueFlow=42.3
384384
end
385385

386386
def m43
387387
a = [0, 1, source(43.1), source(43.2)]
388388
b = a.drop_while do |x|
389-
sink x # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
389+
sink x # $ hasValueFlow=43.1 hasValueFlow=43.2
390390
end
391-
sink(b[0]) # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
391+
sink(b[0]) # $ hasValueFlow=43.1 hasValueFlow=43.2
392392
end
393393

394394
def m44
@@ -1464,7 +1464,7 @@ def m121(i)
14641464
sink(b[i]) # $ hasValueFlow=121.1 $ hasValueFlow=121.2
14651465
a[i] = source(121.3)
14661466
b = a.take(3)
1467-
sink(b[2]) # $ hasValueFlow=121.1 # $ hasValueFlow=121.3
1467+
sink(b[2]) # $ hasValueFlow=121.1 hasValueFlow=121.3
14681468
end
14691469

14701470
def m122

‎ruby/ql/test/library-tests/dataflow/call-sensitivity/call_sensitivity.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def call_method3 x
6868
end
6969

7070
def self.singleton_method1 x
71-
sink x # $ hasValueFlow=14 $ hasValueFlow=15 # $ hasValueFlow=16 $ hasValueFlow=17
71+
sink x # $ hasValueFlow=14 hasValueFlow=15 hasValueFlow=16 hasValueFlow=17
7272
end
7373

7474
def method4(x, y)

‎ruby/ql/test/library-tests/dataflow/hash-flow/hash_flow.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def m43()
715715
:c => taint(43.2)
716716
}
717717
a = hash.values
718-
sink (a[0]) # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
718+
sink (a[0]) # $ hasValueFlow=43.1 hasValueFlow=43.2
719719
end
720720

721721
m43()

‎shared/util/codeql/util/test/InlineExpectationsTest.qll‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ module Make<InlineExpectationsTestSig Impl> {
524524
* is treated as part of the expected results, except that the comment may contain a `//` or `#`
525525
* sequence to treat the remainder of the line as a regular (non-interpreted) comment.
526526
*/
527-
private string expectationCommentPattern() { result = "\\s*\\$ ((?:[^/]|/[^/])*)(?:(//|#).*)?" }
527+
private string expectationCommentPattern() { result = "\\s*\\$ ((?:[^/#]|/[^/])*)(?:(//|#).*)?" }
528528

529529
/**
530530
* The possible columns in an expectation comment. The `TDefaultColumn` branch represents the first
@@ -1180,22 +1180,22 @@ module TestPostProcessing {
11801180
* Holds if `comment` carries a trailing regular (non-interpreted) note `note`, with the note's
11811181
* own comment marker and surrounding whitespace stripped. This is either:
11821182
*
1183-
* - the text after a `//` that follows the expectations in an expectation comment (for example
1184-
* `note` in `// $ Alert // note` or `# $ Alert // note`), which the framework treats as an
1185-
* ordinary comment (see `expectationCommentPattern`); or
1183+
* - the text after a `//` or `#` that follows the expectations in an expectation comment (for
1184+
* example `note` in `// $ Alert // note`, `# $ Alert // note`, or
1185+
* `# $ Alert # note`), which the framework treats as an ordinary comment (see
1186+
* `expectationCommentPattern`); or
11861187
* - the whole content of a plain comment that carries no expectation at all (for example `note`
11871188
* in `// note` or `# note`), into which `--learn` may merge a freshly learned tag.
11881189
*
11891190
* `codeql test run --learn` keeps this note when it rewrites, deletes, or merges into the
11901191
* comment, re-wrapping it with the appropriate markers (`<marker> $ ... // note` when
11911192
* expectations remain, or `<marker> note` when none do), so an explanatory note written next to
1192-
* code is never lost. Only `//` delimits such a note within an expectation comment, mirroring
1193-
* `expectationCommentPattern`'s `(?:[^/]|/[^/])*` expectation region, which ends only at `//`; a
1194-
* `#` never does, so `# $ Alert # note` reads `note` as a tag rather than a note.
1193+
* code is never lost.
11951194
*/
11961195
private string getTrailingNote(TestImpl2::ExpectationComment comment) {
11971196
(
1198-
result = comment.getContents().regexpCapture("\\s*\\$ (?:[^/]|/[^/])*//(.*)", 1).trim()
1197+
result =
1198+
comment.getContents().regexpCapture("\\s*\\$ (?:[^/#]|/[^/])*(?://|#)(.*)", 1).trim()
11991199
or
12001200
// A plain comment with no expectation of its own: its whole content is the note.
12011201
not hasExpectation(comment, _, _, _, _) and

0 commit comments

Comments
 (0)