Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Bugfix - Remove partial ANSI colour codes when truncating object.inspect #294

Merged
merged 1 commit into from
Aug 27, 2016

Conversation

ansonK
Copy link
Contributor

@ansonK ansonK commented Aug 26, 2016

When truncating an object using ObjectFormatter.format that exceeds the max_formatted_output_length remove any partial ANSI color codes.

This fixes an edge case where partial ANSI color codes eg \e[3 is printed to the terminal which corrupts the output.

eg calling object.inspect = "#<\e[33mClass\e[0m \e[36mname: \e[0m"foobars" \e[36mcount: \e[0m42>"
If this was truncated at the 19th char then the result would be: "#<\e[33mClass\e[0m \e[3"
(which results in an invalid escape code).
This commit will remove the partial ANSI code so the result is now: "#<\e[33mClass\e[0m "

To demonstrate the problem here is a screenshot of an example spec running rspec-support 3.4 with good output:
screen shot 2016-08-26 at 15 44 13

And here is the same spec running rspec-support 3.5 with a bad ANSI code corrupting output:
(The output in the expected [] to include... line contains the bad ANSI code which seems to reset the terminal to the top so the output overwrites)
screen shot 2016-08-26 at 15 42 47

@ansonK ansonK force-pushed the truncate-ansi-color-codes branch from 4cf346c to 83f2193 Compare August 26, 2016 14:58
…he max_formatted_output_length remove any partial ANSI color codes.

This fixes an edge case where partial ANSI color codes eg \e[3 is printed to the terminal which corrupts the output.

eg calling object.inspect = "#<\e[33mClass\e[0m \e[36mname: \e[0m\"foobars\" \e[36mcount: \e[0m42>"
If this was truncated at the 19th char then the result would be: "#<\e[33mClass\e[0m \e[3"
This commit will remove the partial ANSI code so the result is now: "#<\e[33mClass\e[0m "

This fixes an edge case where
@JonRowe JonRowe merged commit 0c2a328 into rspec:master Aug 27, 2016
@JonRowe
Copy link
Member

JonRowe commented Aug 27, 2016

Thanks ❤️

JonRowe added a commit that referenced this pull request Aug 28, 2016
[skip ci]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants