Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove unused rchardet gem

Régis Hanolc72569764603
diff --git a/.licensed.yml b/.licensed.yml
index 2c2e9cccc58..cdbf08b8ead 100644
--- a/.licensed.yml
+++ b/.licensed.yml
@@ -33,7 +33,6 @@ ignored:
- pp # Ruby (default gem)
- prettyprint # Ruby (default gem)
- racc # Ruby (default gem)
- - rchardet # LGPL
- rdoc # Ruby (default gem)
- reline # Ruby (default gem)
- ruby2_keywords # Ruby (default gem)
diff --git a/Gemfile b/Gemfile
index 4430a0cf40f..825ef35a745 100644
--- a/Gemfile
+++ b/Gemfile
@@ -234,7 +234,6 @@ gem "landlock", require: false
gem "sshkey", require: false
-gem "rchardet", require: false
gem "lz4-ruby", require: false, platform: :ruby
gem "sanitize"
diff --git a/Gemfile.lock b/Gemfile.lock
index a91760fe17c..64cd85e90ef 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -560,7 +560,6 @@ GEM
ffi (>= 1.0.6)
msgpack (>= 0.4.3)
optimist (>= 3.0.0)
- rchardet (1.10.2)
rdoc (8.0.0)
erb
prism (>= 1.6.0)
@@ -940,7 +939,6 @@ DEPENDENCIES
rake
rb-fsevent
rbtrace
- rchardet
redcarpet
redis
redis-namespace
@@ -1228,7 +1226,6 @@ CHECKSUMS
rb-inotify (0.11.1) sha256=a0a700441239b0ff18eb65e3866236cd78613d6b9f78fea1f9ac47a85e47be6e
rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674
rbtrace (0.5.5) sha256=ed0200ffeac4251f3464412e52f36cd64c473673c2739129e0b48c568672fe68
- rchardet (1.10.2) sha256=e041cb195f464dc10e49ab130f78c8b5956cd9a4f4f6df84e0c183b87c135f33
rdoc (8.0.0) sha256=03bf8c08a9639658855a0cfd77c0abca8325c227693f7f33f82957811348c469
redcarpet (3.6.1) sha256=d444910e6aa55480c6bcdc0cdb057626e8a32c054c29e793fa642ba2f155f445
redis (6.0.0) sha256=de71c10edd106986b759ec7ecdd08b63b9c0ee7414a0d0c1da73d31ba2bccda6
diff --git a/lib/encodings.rb b/lib/encodings.rb
index f78de14a602..b7e42fd2584 100644
--- a/lib/encodings.rb
+++ b/lib/encodings.rb
@@ -1,27 +1,8 @@
# frozen_string_literal: true
-require "rchardet"
-
module Encodings
BOM = "\u{FEFF}"
- def self.to_utf8(string)
- result = CharDet.detect(string)
-
- encoded_string = try_utf8(string, result["encoding"]) if result && result["encoding"]
- encoded_string = force_utf8(string) if encoded_string.nil?
- encoded_string
- end
-
- def self.try_utf8(string, source_encoding)
- encoded = string.encode(Encoding::UTF_8, source_encoding)
- encoded&.valid_encoding? ? delete_bom!(encoded) : nil
- rescue Encoding::InvalidByteSequenceError,
- Encoding::UndefinedConversionError,
- Encoding::ConverterNotFoundError
- nil
- end
-
def self.force_utf8(string)
encoded_string = string.encode(Encoding::UTF_8, undef: :replace, invalid: :replace, replace: "")
delete_bom!(encoded_string)
diff --git a/spec/fixtures/encodings/iso-8859-5.txt b/spec/fixtures/encodings/iso-8859-5.txt
deleted file mode 100644
index 0501b5848df..00000000000
--- a/spec/fixtures/encodings/iso-8859-5.txt
+++ /dev/null
@@ -1 +0,0 @@
-������������ ���������� �� ������ ������������ ��� ��������� ������ ������������� ������������ ���, ��� ������ ������������� � ��������� ������ � ������ ����� �� ���� �����
\ No newline at end of file
diff --git a/spec/fixtures/encodings/utf-16be.txt b/spec/fixtures/encodings/utf-16be.txt
deleted file mode 100644
index 24ca7e99a5c..00000000000
Binary files a/spec/fixtures/encodings/utf-16be.txt and /dev/null differ
diff --git a/spec/fixtures/encodings/utf-16le.txt b/spec/fixtures/encodings/utf-16le.txt
deleted file mode 100644
index 3e3b1ee0d17..00000000000
Binary files a/spec/fixtures/encodings/utf-16le.txt and /dev/null differ
diff --git a/spec/fixtures/encodings/utf-8-bom.txt b/spec/fixtures/encodings/utf-8-bom.txt
deleted file mode 100644
index 4a8c90804da..00000000000
--- a/spec/fixtures/encodings/utf-8-bom.txt
+++ /dev/null
@@ -1 +0,0 @@
-Το σύστημα γραφής είναι ένα συμβολικό, οπτικό σύστημα καταγραφής της γλώσσας.
\ No newline at end of file
diff --git a/spec/lib/encodings_spec.rb b/spec/lib/encodings_spec.rb
index bfa7e635b4b..3db2e416f3f 100644
--- a/spec/lib/encodings_spec.rb
+++ b/spec/lib/encodings_spec.rb
@@ -1,36 +1,11 @@
# frozen_string_literal: true
RSpec.describe Encodings do
- def to_utf8(filename)
- string = File.read("#{Rails.root.join("spec/fixtures/encodings/#{filename}")}").chomp
- Encodings.to_utf8(string)
+ it "strips a leading BOM" do
+ expect(Encodings.delete_bom!(+"#{Encodings::BOM}hello")).to eq("hello")
end
- describe "unicode" do
- let(:expected) do
- "Το σύστημα γραφής είναι ένα συμβολικό, οπτικό σύστημα καταγραφής της γλώσσας."
- end
-
- it "correctly encodes UTF-8 as UTF-8" do
- expect(to_utf8("utf-8.txt")).to eq(expected)
- end
-
- it "correctly encodes UTF-8 with BOM as UTF-8" do
- expect(to_utf8("utf-8-bom.txt")).to eq(expected)
- end
-
- it "correctly encodes UTF-16LE with BOM as UTF-8" do
- expect(to_utf8("utf-16le.txt")).to eq(expected)
- end
-
- it "correctly encodes UTF-16BE with BOM as UTF-8" do
- expect(to_utf8("utf-16be.txt")).to eq(expected)
- end
- end
-
- it "correctly encodes ISO-8859-5 as UTF-8" do
- expect(to_utf8("iso-8859-5.txt")).to eq(
- "Письменность отличается от других существующих или возможных систем символической коммуникации тем, что всегда ассоциируется с некоторым языком и устной речью на этом языке",
- )
+ it "replaces invalid bytes" do
+ expect(Encodings.force_utf8("caf\xFFe")).to eq("cafe")
end
end