Skip to content

Conversation

@trinistr
Copy link
Contributor

From #1016

Ruby no longer escapes control characters and backslashes in an error message. [Feature #18367]

end

it "is not modified with extra escaping of control characters and backslashes" do
out = ruby_exe('raise "\e[31mRed\x1b[0m error\\\message"', args: "2>&1", exit_status: 1)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
out = ruby_exe('raise "\e[31mRed\x1b[0m error\\\message"', args: "2>&1", exit_status: 1)
out = ruby_exe('raise "\e[31mRed\e[0m error\\\message"', args: "2>&1", exit_status: 1)

\x1b -> \e happens during parsing the string literal so it's not really relevant to test here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, copypasted from the issue and didn't look too closely.

end

it "is not modified with extra escaping of control characters and backslashes" do
out = ruby_exe('raise "\e[31mRed\x1b[0m error\\\message"', args: "2>&1", exit_status: 1)
Copy link
Member

Choose a reason for hiding this comment

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

Why the \\\? (3 of them)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Single-quoted string turns \\ into \, and we need two backslashes inside the double-quoted string, so this needs 3 or 4 backslashes to output 1.

Copy link
Member

Choose a reason for hiding this comment

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

Let's do 4 then, 3 is quite hard to figure out and feels hacky

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Actually, there seems to be no spec for backslash escaping at all, at least in language/string_spec.rb? Regexp quoting is probably relevant, but it relies on this.

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

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

Looks good

@trinistr trinistr force-pushed the test-no-escaping-errors branch from 9226f3a to ad917a9 Compare February 2, 2026 13:27
Ruby no longer escapes control characters and backslashes in an
error message. [Feature #18367]
@trinistr trinistr force-pushed the test-no-escaping-errors branch from ad917a9 to 8877450 Compare February 2, 2026 13:37
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.

2 participants