Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace invalid characters with a placeholder #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/spec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
expect({a: "b", c: "d"}).to eql({a: 2, c: 4})
end

it "replaces naughty \0 and \e characters, \x01 and \uFFFF too" do
it "replaces naughty \0 and \e characters, \x01 and \uFFFF too, and \xF0" do
expect("\0\0\0").to eql("emergency services")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec_junit_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def xml_dump_output(example)

def escape(text)
# Make sure it's utf-8, replace illegal characters with ruby-like escapes, and replace special and discouraged characters with entities
text.to_s.encode(Encoding::UTF_8).gsub(ILLEGAL_REGEXP, ILLEGAL_REPLACEMENT).gsub(DISCOURAGED_REGEXP, DISCOURAGED_REPLACEMENTS)
text.to_s.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '??invalid??').gsub(ILLEGAL_REGEXP, ILLEGAL_REPLACEMENT).gsub(DISCOURAGED_REGEXP, DISCOURAGED_REPLACEMENTS)
end

STRIP_DIFF_COLORS_BLOCK_REGEXP = /^ ( [ ]* ) Diff: (?: \e\[ 0 m )? (?: \n \1 \e\[ \d+ (?: ; \d+ )* m .* )* /x
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec_junit_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def execute_example_spec

# it correctly replaces illegal characters

expect(doc.xpath("//testcase[contains(@name, 'naughty')]").first[:name]).to eql("some example specs replaces naughty \\0 and \\e characters, \\x01 and \\uFFFF too")
expect(doc.xpath("//testcase[contains(@name, 'naughty')]").first[:name]).to eql("some example specs replaces naughty \\0 and \\e characters, \\x01 and \\uFFFF too, and ??invalid??")

# it correctly escapes discouraged characters

Expand Down