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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:

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)