Rust: Handle string literals with line breaks#20871
Merged
paldepind merged 2 commits intogithub:mainfrom Nov 19, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where string literals with line breaks were not being properly recognized. The issue occurred because the previous regex pattern using . didn't match newline characters.
Key Changes:
- Simplified the
StringLiteralExprimplementation to check only the first character instead of using a regex - Added test cases for multi-line string literals (both normal and raw strings)
- Updated expected test outputs to reflect the new string literal entries
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
rust/ql/test/extractor-tests/literal/literal.rs |
Added test cases for multi-line normal and raw string literals |
rust/ql/test/extractor-tests/literal/literal.expected |
Updated expected output with new string literal entries and adjusted line numbers for subsequent tests |
rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll |
Simplified string literal detection from regex to first-character check, fixing newline handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hvitved
approved these changes
Nov 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We currently do not handle string literals with line breaks. This is because
.doesn't match newlines.This PR simplifies the implementation to not use a regexp, but instead just checks the first character which relies on the fact that only string literals can start with
"and only raw string literals can start withr.