Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ private module Impl implements RegexTreeViewSig {
// Find the opening '"'.
not re instanceof RawStringLiteral and
result = 1 + min(int i | vt.charAt(i) = "\"")
or
// No opening '"'.
not re instanceof RawStringLiteral and
not exists(int i | vt.charAt(i) = "\"") and
result = 0
Comment on lines +225 to +229

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have the same problem for raw string literals, but then for (?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's possible to stringify into raw string literals, yes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in fact right now no, due to the way you define RawStringLiteral it must contain a (. But it's fragile to depend on that.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be less fragile if we defined getContentOffset() in StringLiteral and RawStringLiteral. That way the definition that depends on ( being present is close to the constructor that ensures it, so it seems less fragile as a future developer working on RawStringLiteral ought to be aware of both.

How do you feel about the direction of providing the functionality of regexpContentOffset in StringLiteral?

)
}

Expand Down
3 changes: 3 additions & 0 deletions cpp/ql/test/library-tests/regex/locations.expected
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@
| regexp.cpp:120:41:120:44 | a\\nc | regexp.cpp | 120 | 41 | 120 | 44 |
| regexp.cpp:121:25:121:28 | a\\nc | regexp.cpp | 121 | 25 | 121 | 28 |
| regexp.cpp:122:29:122:32 | a\\nc | regexp.cpp | 122 | 29 | 122 | 32 |
| regexp.cpp:127:29:127:32 | abc1 | regexp.cpp | 127 | 29 | 127 | 32 |
| regexp.cpp:128:35:128:38 | abc2 | regexp.cpp | 128 | 35 | 128 | 38 |
| regexp.cpp:129:25:129:30 | xabc3x | regexp.cpp | 129 | 25 | 129 | 30 |
6 changes: 6 additions & 0 deletions cpp/ql/test/library-tests/regex/parse.expected
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,9 @@ regexp.cpp:
# 122| [RegExpConstant, RegExpEscape] \n

# 122| [RegExpConstant, RegExpNormalChar] c

# 127| [RegExpConstant, RegExpNormalChar] abc1

# 128| [RegExpConstant, RegExpNormalChar] abc2

# 129| [RegExpConstant, RegExpNormalChar] xabc3x
7 changes: 7 additions & 0 deletions cpp/ql/test/library-tests/regex/regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,10 @@ std::basic_regex<char16_t> r_loc_uR(uR"(a\nc)");
std::basic_regex<char32_t> r_loc_UR(UR"(a\nc)");
std::regex r_loc_Rx(R"x(a\nc)x");
std::regex r_loc_Rfoo(R"foo(a\nc)foo");

// Composite and stringified string literals
#define STRINGIFY(str) #str
#define WRAP(str) "x" #str "x"
std::regex r_loc_composite("ab" "c1");
std::regex r_loc_macro1(STRINGIFY(abc2));
std::regex r_loc_macro2(WRAP(abc3));
6 changes: 6 additions & 0 deletions cpp/ql/test/library-tests/regex/regexp.expected
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ term
| regexp.cpp:122:29:122:32 | a\\nc | RegExpSequence |
| regexp.cpp:122:30:122:31 | \\n | RegExpConstant,RegExpEscape |
| regexp.cpp:122:32:122:32 | c | RegExpConstant,RegExpNormalChar |
| regexp.cpp:127:29:127:32 | abc1 | RegExpConstant,RegExpNormalChar |
| regexp.cpp:128:35:128:38 | abc2 | RegExpConstant,RegExpNormalChar |
| regexp.cpp:129:25:129:30 | xabc3x | RegExpConstant,RegExpNormalChar |
regExpNormalCharValue
| regexp.cpp:18:19:18:21 | abc | abc |
| regexp.cpp:21:20:21:20 | a | a |
Expand Down Expand Up @@ -362,3 +365,6 @@ regExpNormalCharValue
| regexp.cpp:122:29:122:29 | a | a |
| regexp.cpp:122:30:122:31 | \\n | \n |
| regexp.cpp:122:32:122:32 | c | c |
| regexp.cpp:127:29:127:32 | abc1 | abc1 |
| regexp.cpp:128:35:128:38 | abc2 | abc2 |
| regexp.cpp:129:25:129:30 | xabc3x | xabc3x |