Skip to content

Commit 0e539db

Browse files
committed
Rust: Handle string literals with line breaks
1 parent 481f627 commit 0e539db

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module Impl {
6868
* [1]: https://doc.rust-lang.org/reference/tokens.html#string-literals
6969
*/
7070
class StringLiteralExpr extends LiteralExpr {
71-
StringLiteralExpr() { this.getTextValue().regexpMatch("r?#*\".*\"#*") }
71+
StringLiteralExpr() { this.getTextValue().charAt(0) = ["\"", "r"] }
7272

7373
override string getAPrimaryQlClass() { result = "StringLiteralExpr" }
7474
}

rust/ql/test/extractor-tests/literal/literal.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ stringLiteral
1616
| literal.rs:21:5:21:8 | r"R" |
1717
| literal.rs:22:5:22:11 | "\\\\x52" |
1818
| literal.rs:23:5:23:11 | r"\\x52" |
19+
| literal.rs:25:5:29:5 | "\n A normal string literal\n... |
20+
| literal.rs:31:5:34:6 | r#"\n A raw string literal\n ... |
1921
integerLiteral
2022
| literal.rs:39:5:39:7 | 123 | |
2123
| literal.rs:40:5:40:10 | 123i32 | i32 |

0 commit comments

Comments
 (0)