Skip to content

Commit e236edc

Browse files
hsbtclaude
andcommitted
Scrub invalid bytes when normalizing command output
When captured subprocess output contained a byte that isn't valid UTF-8, normalize tagged the buffer as UTF-8 and then ran gsub over it, which scans the whole string and raised Encoding::CompatibilityError: invalid byte sequence in UTF-8. The error surfaced from inside the test harness rather than on an assertion, so RSpec reported "Unable to find matching line from backtrace" and the real output was lost. Scrub the string after forcing the encoding so normalize never raises on malformed bytes, and dup it first so forcing the encoding no longer mutates the stored capture buffer. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0365a17 commit e236edc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

spec/support/command_execution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def failure?
7272
attr_reader :failure_reason
7373

7474
def normalize(string)
75-
string.force_encoding(Encoding::UTF_8).strip.gsub("\r\n", "\n")
75+
string.dup.force_encoding(Encoding::UTF_8).scrub.strip.gsub("\r\n", "\n")
7676
end
7777
end
7878
end

0 commit comments

Comments
 (0)