Skip to content

Don't split escaped backslashes when reflowing long string literals. - #1513

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1009611290
Oct 30, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1009611290

Conversation

@copybara-service

Copy link
Copy Markdown

Don't split escaped backslashes when reflowing long string literals.

When splitting a long string literal, StringWrapper looked for \t, \n and \r escapes at every position in the literal's source, without tracking whether the backslash was itself escaped. So an escaped backslash followed by t, n or r (for example \\t in a Windows path or a regular expression) was split between the two backslashes, producing an unterminated string literal or a string with different contents. The safety check after wrapping then rejected the change, and formatting failed with an error.

StringWrapper now skips over each escape sequence as a unit, so only real escapes are treated as places to split.

Fixes #1186
Fixes #1253
Fixes #1439

When splitting a long string literal, `StringWrapper` looked for `\t`, `\n` and `\r` escapes at every position in the literal's source, without tracking whether the backslash was itself escaped. So an escaped backslash followed by `t`, `n` or `r` (for example `\\t` in a Windows path or a regular expression) was split between the two backslashes, producing an unterminated string literal or a string with different contents. The safety check after wrapping then rejected the change, and formatting failed with an error.

`StringWrapper` now skips over each escape sequence as a unit, so only real escapes are treated as places to split.

Fixes #1186
Fixes #1253
Fixes #1439

PiperOrigin-RevId: 1010274507
@copybara-service
copybara-service Bot merged commit 7e4696d into master Oct 30, 2026
@copybara-service
copybara-service Bot deleted the test_1009611290 branch October 30, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant