jerska-htmlentities 4.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING.txt +21 -0
- data/History.txt +89 -0
- data/lib/htmlentities.rb +75 -0
- data/lib/htmlentities/decoder.rb +56 -0
- data/lib/htmlentities/encoder.rb +123 -0
- data/lib/htmlentities/flavors.rb +9 -0
- data/lib/htmlentities/mappings/expanded.rb +1074 -0
- data/lib/htmlentities/mappings/html4.rb +257 -0
- data/lib/htmlentities/mappings/xhtml1.rb +258 -0
- data/lib/htmlentities/version.rb +9 -0
- data/perf/benchmark.rb +13 -0
- data/perf/performance.rb +31 -0
- data/perf/profile.rb +17 -0
- data/test/decoding_test.rb +164 -0
- data/test/encoding_test.rb +106 -0
- data/test/entities_test.rb +24 -0
- data/test/expanded_test.rb +109 -0
- data/test/html4_test.rb +25 -0
- data/test/interoperability_test.rb +15 -0
- data/test/roundtrip_test.rb +67 -0
- data/test/string_encodings_test.rb +68 -0
- data/test/test_helper.rb +3 -0
- data/test/xhtml1_test.rb +24 -0
- metadata +91 -0
data/test/html4_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative "./test_helper"
|
3
|
+
|
4
|
+
class HTML4Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_reader :html_entities
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@html_entities = HTMLEntities.new('html4')
|
10
|
+
end
|
11
|
+
|
12
|
+
# Found by Marcos Kuhns
|
13
|
+
def test_should_not_encode_apos_entity
|
14
|
+
assert_equal "'", html_entities.encode("'", :basic)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_not_decode_apos_entity
|
18
|
+
assert_equal "é'", html_entities.decode("é'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_not_decode_dotted_entity
|
22
|
+
assert_equal "&b.Theta;", html_entities.decode("&b.Theta;")
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative "./test_helper"
|
3
|
+
|
4
|
+
if ENV["RUN_INTEROPERABILITY_TESTS"]
|
5
|
+
class HTMLEntities::InteroperabilityTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_should_encode_active_support_safe_buffer
|
8
|
+
require 'active_support'
|
9
|
+
string = "<p>This is a test</p>"
|
10
|
+
buffer = ActiveSupport::SafeBuffer.new(string)
|
11
|
+
coder = HTMLEntities.new
|
12
|
+
assert_equal coder.encode(string, :named), coder.encode(buffer, :named)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative "./test_helper"
|
3
|
+
|
4
|
+
class HTMLEntities::RoundtripTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_reader :xhtml1_entities, :html4_entities
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@xhtml1_entities = HTMLEntities.new('xhtml1')
|
10
|
+
@html4_entities = HTMLEntities.new('html4')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_roundtrip_xhtml1_entities_via_named_encoding
|
14
|
+
each_mapping 'xhtml1' do |name, string|
|
15
|
+
assert_equal string, xhtml1_entities.decode(xhtml1_entities.encode(string, :named))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_roundtrip_xhtml1_entities_via_basic_and_named_encoding
|
20
|
+
each_mapping 'xhtml1' do |name, string|
|
21
|
+
assert_equal string, xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_roundtrip_xhtml1_entities_via_basic_named_and_decimal_encoding
|
26
|
+
each_mapping 'xhtml1' do |name, string|
|
27
|
+
assert_equal string, xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named, :decimal))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_roundtrip_xhtml1_entities_via_hexadecimal_encoding
|
32
|
+
each_mapping 'xhtml1' do |name, string|
|
33
|
+
assert_equal string, xhtml1_entities.decode(xhtml1_entities.encode(string, :hexadecimal))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_roundtrip_html4_entities_via_named_encoding
|
38
|
+
each_mapping 'html4' do |name, string|
|
39
|
+
assert_equal string, html4_entities.decode(html4_entities.encode(string, :named))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_roundtrip_html4_entities_via_basic_and_named_encoding
|
44
|
+
each_mapping 'html4' do |name, string|
|
45
|
+
assert_equal string, html4_entities.decode(html4_entities.encode(string, :basic, :named))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_roundtrip_html4_entities_via_basic_named_and_decimal_encoding
|
50
|
+
each_mapping 'html4' do |name, string|
|
51
|
+
assert_equal string, html4_entities.decode(html4_entities.encode(string, :basic, :named, :decimal))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_roundtrip_html4_entities_via_hexadecimal_encoding
|
56
|
+
each_mapping 'html4' do |name, string|
|
57
|
+
assert_equal string, html4_entities.decode(html4_entities.encode(string, :hexadecimal))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def each_mapping(flavor)
|
62
|
+
HTMLEntities::MAPPINGS[flavor].each do |name, codepoint|
|
63
|
+
yield name, [codepoint].pack('U')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative "./test_helper"
|
3
|
+
|
4
|
+
class HTMLEntities::StringEncodingsTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_should_encode_ascii_to_ascii
|
7
|
+
s = "<elan>".encode(Encoding::US_ASCII)
|
8
|
+
assert_equal Encoding::US_ASCII, s.encoding
|
9
|
+
|
10
|
+
t = HTMLEntities.new.encode(s)
|
11
|
+
assert_equal "<elan>", t
|
12
|
+
assert_equal Encoding::US_ASCII, t.encoding
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_encode_utf8_to_utf8_if_needed
|
16
|
+
s = "<élan>"
|
17
|
+
assert_equal Encoding::UTF_8, s.encoding
|
18
|
+
|
19
|
+
t = HTMLEntities.new.encode(s)
|
20
|
+
assert_equal "<élan>", t
|
21
|
+
assert_equal Encoding::UTF_8, t.encoding
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_encode_utf8_to_ascii_if_possible
|
25
|
+
s = "<elan>"
|
26
|
+
assert_equal Encoding::UTF_8, s.encoding
|
27
|
+
|
28
|
+
t = HTMLEntities.new.encode(s)
|
29
|
+
assert_equal "<elan>", t
|
30
|
+
assert_equal Encoding::US_ASCII, t.encoding
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_encode_other_encoding_to_utf8
|
34
|
+
s = "<élan>".encode(Encoding::ISO_8859_1)
|
35
|
+
assert_equal Encoding::ISO_8859_1, s.encoding
|
36
|
+
|
37
|
+
t = HTMLEntities.new.encode(s)
|
38
|
+
assert_equal "<élan>", t
|
39
|
+
assert_equal Encoding::UTF_8, t.encoding
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_decode_ascii_to_utf8
|
43
|
+
s = "<élan>".encode(Encoding::US_ASCII)
|
44
|
+
assert_equal Encoding::US_ASCII, s.encoding
|
45
|
+
|
46
|
+
t = HTMLEntities.new.decode(s)
|
47
|
+
assert_equal "<élan>", t
|
48
|
+
assert_equal Encoding::UTF_8, t.encoding
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_decode_utf8_to_utf8
|
52
|
+
s = "<élan>".encode(Encoding::UTF_8)
|
53
|
+
assert_equal Encoding::UTF_8, s.encoding
|
54
|
+
|
55
|
+
t = HTMLEntities.new.decode(s)
|
56
|
+
assert_equal "<élan>", t
|
57
|
+
assert_equal Encoding::UTF_8, t.encoding
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_decode_other_encoding_to_utf8
|
61
|
+
s = "<élan>".encode(Encoding::ISO_8859_1)
|
62
|
+
assert_equal Encoding::ISO_8859_1, s.encoding
|
63
|
+
|
64
|
+
t = HTMLEntities.new.decode(s)
|
65
|
+
assert_equal "<élan>", t
|
66
|
+
assert_equal Encoding::UTF_8, t.encoding
|
67
|
+
end
|
68
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/xhtml1_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative "./test_helper"
|
3
|
+
|
4
|
+
class HTMLEntities::XHTML1Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_reader :html_entities
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@html_entities = HTMLEntities.new('xhtml1')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_encode_apos_entity
|
13
|
+
assert_equal "'", html_entities.encode("'", :basic)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_decode_apos_entity
|
17
|
+
assert_equal "é'", html_entities.decode("é'")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_not_decode_dotted_entity
|
21
|
+
assert_equal "&b.Theta;", html_entities.decode("&b.Theta;")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jerska-htmlentities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthieu Dumont (on work of Paul Battley)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A module for encoding and decoding (X)HTML entities.
|
28
|
+
email: jerska@live.fr
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- COPYING.txt
|
34
|
+
files:
|
35
|
+
- COPYING.txt
|
36
|
+
- History.txt
|
37
|
+
- lib/htmlentities.rb
|
38
|
+
- lib/htmlentities/decoder.rb
|
39
|
+
- lib/htmlentities/encoder.rb
|
40
|
+
- lib/htmlentities/flavors.rb
|
41
|
+
- lib/htmlentities/mappings/expanded.rb
|
42
|
+
- lib/htmlentities/mappings/html4.rb
|
43
|
+
- lib/htmlentities/mappings/xhtml1.rb
|
44
|
+
- lib/htmlentities/version.rb
|
45
|
+
- perf/benchmark.rb
|
46
|
+
- perf/performance.rb
|
47
|
+
- perf/profile.rb
|
48
|
+
- test/decoding_test.rb
|
49
|
+
- test/encoding_test.rb
|
50
|
+
- test/entities_test.rb
|
51
|
+
- test/expanded_test.rb
|
52
|
+
- test/html4_test.rb
|
53
|
+
- test/interoperability_test.rb
|
54
|
+
- test/roundtrip_test.rb
|
55
|
+
- test/string_encodings_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
- test/xhtml1_test.rb
|
58
|
+
homepage: https://github.com/Jerska/htmlentities
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.6.14
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Encode/decode HTML entities
|
82
|
+
test_files:
|
83
|
+
- test/string_encodings_test.rb
|
84
|
+
- test/entities_test.rb
|
85
|
+
- test/encoding_test.rb
|
86
|
+
- test/interoperability_test.rb
|
87
|
+
- test/roundtrip_test.rb
|
88
|
+
- test/html4_test.rb
|
89
|
+
- test/expanded_test.rb
|
90
|
+
- test/decoding_test.rb
|
91
|
+
- test/xhtml1_test.rb
|