Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v0.7.10-compatibillity-for-m1' i…
Browse files Browse the repository at this point in the history
…nto v0.7.10-compatibillity-for-m1
  • Loading branch information
restot committed Feb 10, 2025
2 parents 061eea6 + 2be284b commit b2202f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ext/charlock_holmes/encoding_detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ static VALUE rb_encdec_binarymatch(void) {
rb_match = rb_hash_new();

rb_hash_aset(rb_match, ID2SYM(rb_intern("type")), ID2SYM(rb_intern("binary")));
rb_hash_aset(rb_match, ID2SYM(rb_intern("encoding")), charlock_new_str2("BINARY"));
rb_hash_aset(rb_match, ID2SYM(rb_intern("ruby_encoding")), charlock_new_str2("ASCII-8BIT"));
rb_hash_aset(rb_match, ID2SYM(rb_intern("confidence")), INT2NUM(100));

return rb_match;
Expand Down
18 changes: 11 additions & 7 deletions test/encoding_detector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def test_returns_a_ruby_compatible_encoding_name
detected = @detector.detect not_compat_txt
assert_equal 'ISO-2022-KR', detected[:encoding]
assert_equal 'binary', detected[:ruby_encoding]

detected = @detector.detect "\0\0"
assert_equal 'BINARY', detected[:encoding]
assert_equal 'ASCII-8BIT', detected[:ruby_encoding]
end

def test_is_binary
Expand All @@ -132,13 +136,13 @@ def test_is_binary
['utf16be.html', 'UTF-16BE', :text],
['utf32le.html', 'UTF-32LE', :text],
['utf32be.html', 'UTF-32BE', :text],
['hello_world', nil, :binary],
['octocat.png', nil, :binary],
['octocat.jpg', nil, :binary],
['octocat.psd', nil, :binary],
['octocat.gif', nil, :binary],
['octocat.ai', nil, :binary],
['foo.pdf', nil, :binary],
['hello_world', 'BINARY', :binary],
['octocat.png', 'BINARY', :binary],
['octocat.jpg', 'BINARY', :binary],
['octocat.psd', 'BINARY', :binary],
['octocat.gif', 'BINARY', :binary],
['octocat.ai', 'BINARY', :binary],
['foo.pdf', 'BINARY', :binary],
]

def test_detection_works_as_expected
Expand Down

0 comments on commit b2202f6

Please sign in to comment.