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

AO3-6087 Stop removing non-printable Unicode characters #4798

Merged
merged 2 commits into from
May 17, 2024
Merged
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
5 changes: 0 additions & 5 deletions lib/html_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ def fix_bad_characters(text)
# argh, get rid of ____spacer____ inserts
text.gsub! "____spacer____", ""

# trash a whole bunch of crappy non-printing format characters stuck
# in most commonly by MS Word
# \p{Cf} matches all unicode char in the "other, format" category
text.gsub!(/\p{Cf}/u, '')

return text
end

Expand Down
19 changes: 15 additions & 4 deletions spec/lib/html_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,21 @@
expect(fix_bad_characters("„‚nörmäl’—téxt‘“")).to eq("„‚nörmäl’—téxt‘“")
end

it "does not touch zero-width non-joiner" do
string = ["A".ord, 0x200C, "A".ord] # "A[zwnj]A"
expect(fix_bad_characters(string.pack("U*")).unpack("U*")).to eq(string)
end

it "does not touch zero-width joiner" do
string = ["A".ord, 0x200D, "A".ord] # "A[zwj]A"
expect(fix_bad_characters(string.pack("U*")).unpack("U*")).to eq(string)
end

it "does not touch word joiner" do
string = ["A".ord, 0x2060, "A".ord] # "A[wj]A"
expect(fix_bad_characters(string.pack("U*")).unpack("U*")).to eq(string)
end

it "should remove invalid unicode chars" do
bad_string = [65, 150, 65].pack("C*") # => "A\226A"
expect(fix_bad_characters(bad_string)).to eq("AA")
Expand All @@ -540,10 +555,6 @@
it "should remove the spacer" do
expect(fix_bad_characters("A____spacer____A")).to eq("AA")
end

it "should remove unicode chars in the 'other, format' category" do
expect(fix_bad_characters("A\xE2\x81\xA0A")).to eq("AA")
end
end

describe "add_paragraphs_to_text" do
Expand Down
Loading