Skip to content

Commit c0c8958

Browse files
committed
Ruby: Implement inline expectation comments for .erb files.
1 parent 0ee4041 commit c0c8958

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

ruby/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,51 @@ private import codeql.util.test.InlineExpectationsTest
44
module Impl implements InlineExpectationsTestSig {
55
private import codeql.ruby.ast.internal.TreeSitter
66

7+
private newtype TAnyComment =
8+
RubyComment(Ruby::Comment comment) or
9+
ErbComment(R::ErbComment comment)
10+
11+
private class AnyComment extends TAnyComment {
12+
string toString() {
13+
exists(Ruby::Comment c |
14+
this = RubyComment(c) and
15+
result = c.toString()
16+
)
17+
or
18+
exists(R::ErbComment c |
19+
this = ErbComment(c) and
20+
result = c.toString()
21+
)
22+
}
23+
24+
Location getLocation() {
25+
exists(Ruby::Comment c |
26+
this = RubyComment(c) and
27+
result = c.getLocation()
28+
)
29+
or
30+
exists(R::ErbComment c |
31+
this = ErbComment(c) and
32+
result = c.getLocation()
33+
)
34+
}
35+
}
36+
737
/**
838
* A class representing line comments in Ruby.
939
*/
10-
class ExpectationComment extends Ruby::Comment {
11-
string getContents() { result = this.getValue().suffix(1) }
40+
class ExpectationComment extends AnyComment {
41+
string getContents() {
42+
exists(Ruby::Comment c |
43+
this = RubyComment(c) and
44+
result = c.getValue().suffix(1)
45+
)
46+
or
47+
exists(R::ErbComment c |
48+
this = ErbComment(c) and
49+
result = c.getValue().suffix(1)
50+
)
51+
}
1252
}
1353

1454
class Location = R::Location;

ruby/ql/test/library-tests/frameworks/sinatra/Flow.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ nodes
2323
| views/index.erb:2:10:2:12 | call to foo | semmle.label | call to foo |
2424
subpaths
2525
testFailures
26-
| views/index.erb:2:10:2:12 | call to foo | Unexpected result: hasTaintFlow |
2726
#select
2827
| app.rb:95:10:95:14 | @user | app.rb:103:13:103:22 | call to source | app.rb:95:10:95:14 | @user | $@ | app.rb:103:13:103:22 | call to source | call to source |
2928
| views/index.erb:2:10:2:12 | call to foo | app.rb:75:12:75:17 | call to params | views/index.erb:2:10:2:12 | call to foo | $@ | app.rb:75:12:75:17 | call to params | call to params |

0 commit comments

Comments
 (0)