Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Nov 19, 2025

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 with r.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Nov 19, 2025
@paldepind paldepind marked this pull request as ready for review November 19, 2025 12:58
@paldepind paldepind requested a review from a team as a code owner November 19, 2025 12:58
Copilot AI review requested due to automatic review settings November 19, 2025 12:58
Copilot finished reviewing on behalf of paldepind November 19, 2025 13:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 StringLiteralExpr implementation 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.

@paldepind paldepind merged commit 4d9ab7b into github:main Nov 19, 2025
25 of 26 checks passed
@paldepind paldepind deleted the rust/string-literal branch November 19, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants