Skip to content

Commit 29a4969

Browse files
committed
replace invalid sequences with ?
1 parent 39df946 commit 29a4969

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

app/services/import/jira_wiki_markup/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def initialize(text)
5050
# and invalid byte sequences are dropped so downstream regex/StringScanner
5151
# operations cannot raise ArgumentError on malformed input.
5252
@text = text.to_s.dup
53-
@text.scrub!("") unless @text.valid_encoding?
53+
@text.scrub!("?") unless @text.valid_encoding?
5454
end
5555

5656
def parse

spec/services/import/jira_wiki_markup_converter_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,31 @@
5656
it "drops a stray invalid byte and keeps the surrounding text" do
5757
input = "Hello \xFF world".dup
5858
expect(input.valid_encoding?).to be(false)
59-
expect(described_class.new(input).convert).to eq("Hello world")
59+
expect(described_class.new(input).convert).to eq("Hello ? world")
6060
end
6161

6262
it "drops a stray continuation byte" do
6363
input = "abc \x80 def".dup
6464
expect(input.valid_encoding?).to be(false)
65-
expect(described_class.new(input).convert).to eq("abc def")
65+
expect(described_class.new(input).convert).to eq("abc ? def")
6666
end
6767

6868
it "drops a truncated multi-byte sequence" do
6969
input = "pre \xC3 post".dup
7070
expect(input.valid_encoding?).to be(false)
71-
expect(described_class.new(input).convert).to eq("pre post")
71+
expect(described_class.new(input).convert).to eq("pre ? post")
7272
end
7373

7474
it "preserves valid multi-byte characters while dropping only the invalid byte" do
7575
input = "héllo \xFF world".dup
7676
expect(input.valid_encoding?).to be(false)
77-
expect(described_class.new(input).convert).to eq("héllo world")
77+
expect(described_class.new(input).convert).to eq("héllo ? world")
7878
end
7979

8080
it "still parses formatting around invalid bytes inside delimiters" do
8181
input = "*bold\xFFtext*".dup
8282
expect(input.valid_encoding?).to be(false)
83-
expect(described_class.new(input).convert).to eq("**boldtext**")
83+
expect(described_class.new(input).convert).to eq("**bold?text**")
8484
end
8585
end
8686
end

0 commit comments

Comments
 (0)