Skip to content

Fix(FormatRawStringLiteral): Prevent invalid hash removal from single-line multiline strings#3259

Closed
rickhohler wants to merge 1 commit intoswiftlang:mainfrom
rickhohler:fix/sourcekit-lsp-2465-format-raw-string
Closed

Fix(FormatRawStringLiteral): Prevent invalid hash removal from single-line multiline strings#3259
rickhohler wants to merge 1 commit intoswiftlang:mainfrom
rickhohler:fix/sourcekit-lsp-2465-format-raw-string

Conversation

@rickhohler
Copy link
Copy Markdown

Description

This PR fixes a bug in FormatRawStringLiteral where hashes were incorrectly removed from single-line string literals that use multiline quotes (e.g., #"""hello"""#), resulting in invalid Swift syntax ("""hello""").

Detailed changes

  • Modified FormatRawStringLiteral.swift to detect when a string's content is fully wrapped in quotes (handling the ambiguous parsing of #"""..."""#) and when a string uses """ delimiters but has no newlines.
  • In these cases, the refactoring now preserves at least one hash (or the minimal required) to maintain valid syntax.

Fixes

Resolves swiftlang/sourcekit-lsp#2465.

Pre-PR Checklist

  • Code builds and passes tests.
  • Ran swift-format.
  • Added regression test case in FormatRawStringLiteralTest.swift.

@rickhohler
Copy link
Copy Markdown
Author

Closing in favor of #3256 which addresses the same issue and was submitted earlier.

@rickhohler rickhohler closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactoring "Convert string literal to minimal number of '#'s" produces incorrect source code

1 participant