htmlentities 4.3.4 → 4.4.0
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 +5 -5
- data/History.txt +5 -0
- data/lib/htmlentities/decoder.rb +4 -4
- data/lib/htmlentities/encoder.rb +5 -5
- data/lib/htmlentities/version.rb +2 -2
- metadata +49 -33
- data/perf/benchmark.rb +0 -13
- data/perf/performance.rb +0 -31
- data/perf/profile.rb +0 -17
- data/test/decoding_test.rb +0 -101
- data/test/encoding_test.rb +0 -106
- data/test/entities_test.rb +0 -24
- data/test/expanded_test.rb +0 -109
- data/test/html4_test.rb +0 -25
- data/test/interoperability_test.rb +0 -15
- data/test/roundtrip_test.rb +0 -67
- data/test/string_encodings_test.rb +0 -68
- data/test/test_helper.rb +0 -3
- data/test/xhtml1_test.rb +0 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cdf361f9de12e40bc9ed28f9bbf3b641865ce8fc6c018e0b6418ea4384af29cf
|
|
4
|
+
data.tar.gz: 4bb633cdba82e6cad87dd43e9128730dd57ff0a2bf7e702cc2213b280cbe165f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da22d83a074cd62996861db18f64f80c510d1afb3ef5f4b8298d704749645ac564718ce2997843690cdb1b3fcaf0858aa7dcedd881be68742b893e83cd425550
|
|
7
|
+
data.tar.gz: 44e7d7e2b64c88a61a70b77370f71f7ff23de779dbf56f7bd38769000aec72edb8fbe39d8477e4dc84f9a0c5294ebdaa8b7c3a9cd03f3d4059366daa9560a310
|
data/History.txt
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
== 4.4.0 (2025-11-17)
|
|
2
|
+
* Make a few small optimisations.
|
|
3
|
+
* Allow decoding of entities without semicolons at end of line.
|
|
4
|
+
* Remove support for old unsupported Ruby versions (below 3.2).
|
|
5
|
+
|
|
1
6
|
== 4.3.4 (2015-07-05)
|
|
2
7
|
* Remove erroneous 'Iodot' entity (a typo'd duplicate of Idot).
|
|
3
8
|
|
data/lib/htmlentities/decoder.rb
CHANGED
|
@@ -9,11 +9,11 @@ class HTMLEntities
|
|
|
9
9
|
def decode(source)
|
|
10
10
|
prepare(source).gsub(@entity_regexp){
|
|
11
11
|
if $1 && codepoint = @map[$1]
|
|
12
|
-
|
|
12
|
+
codepoint.chr(Encoding::UTF_8)
|
|
13
13
|
elsif $2
|
|
14
|
-
|
|
14
|
+
$2.to_i(10).chr(Encoding::UTF_8)
|
|
15
15
|
elsif $3
|
|
16
|
-
|
|
16
|
+
$3.to_i(16).chr(Encoding::UTF_8)
|
|
17
17
|
else
|
|
18
18
|
$&
|
|
19
19
|
end
|
|
@@ -32,7 +32,7 @@ class HTMLEntities
|
|
|
32
32
|
else
|
|
33
33
|
entity_name_pattern = '[a-z][a-z0-9]'
|
|
34
34
|
end
|
|
35
|
-
/&(?:(#{entity_name_pattern}{#{key_lengths.min - 1},#{key_lengths.max - 1}})|#([0-9]{1,7})|#x([0-9a-f]{1,6}))
|
|
35
|
+
/&(?:(#{entity_name_pattern}{#{key_lengths.min - 1},#{key_lengths.max - 1}})|#([0-9]{1,7})|#x([0-9a-f]{1,6}))(;|(?=\n|<))/i
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
data/lib/htmlentities/encoder.rb
CHANGED
|
@@ -34,11 +34,11 @@ class HTMLEntities
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def contains_only_ascii?(string)
|
|
37
|
-
string.match(/\A[\x01-\x7F]*\z/)
|
|
37
|
+
string.match?(/\A[\x01-\x7F]*\z/)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def basic_entity_regexp
|
|
41
|
-
@basic_entity_regexp ||= @flavor.match(/^html/) ? /[<>"&]/ : /[<>'"&]/
|
|
41
|
+
@basic_entity_regexp ||= @flavor.match?(/^html/) ? /[<>"&]/ : /[<>'"&]/
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def extended_entity_regexp
|
|
@@ -99,16 +99,16 @@ class HTMLEntities
|
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
def encode_named(char)
|
|
102
|
-
cp = char.
|
|
102
|
+
cp = char.codepoints.first
|
|
103
103
|
(e = reverse_map[cp]) && "&#{e};"
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def encode_decimal(char)
|
|
107
|
-
"&##{char.
|
|
107
|
+
"&##{char.codepoints.first};"
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
def encode_hexadecimal(char)
|
|
111
|
-
"&#x#{char.
|
|
111
|
+
"&#x#{char.codepoints.first.to_s(16)};"
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
def reverse_map
|
data/lib/htmlentities/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: htmlentities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Battley
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rake
|
|
@@ -16,12 +15,54 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '13'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '13'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rspec
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3'
|
|
20
33
|
type: :development
|
|
21
34
|
prerelease: false
|
|
22
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
36
|
requirements:
|
|
24
37
|
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '3'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: benchmark
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: ruby-prof
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
25
66
|
- !ruby/object:Gem::Version
|
|
26
67
|
version: '0'
|
|
27
68
|
description: A module for encoding and decoding (X)HTML entities.
|
|
@@ -29,8 +70,8 @@ email: pbattley@gmail.com
|
|
|
29
70
|
executables: []
|
|
30
71
|
extensions: []
|
|
31
72
|
extra_rdoc_files:
|
|
32
|
-
- History.txt
|
|
33
73
|
- COPYING.txt
|
|
74
|
+
- History.txt
|
|
34
75
|
files:
|
|
35
76
|
- COPYING.txt
|
|
36
77
|
- History.txt
|
|
@@ -42,24 +83,10 @@ files:
|
|
|
42
83
|
- lib/htmlentities/mappings/html4.rb
|
|
43
84
|
- lib/htmlentities/mappings/xhtml1.rb
|
|
44
85
|
- 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
86
|
homepage: https://github.com/threedaymonk/htmlentities
|
|
59
87
|
licenses:
|
|
60
88
|
- MIT
|
|
61
89
|
metadata: {}
|
|
62
|
-
post_install_message:
|
|
63
90
|
rdoc_options: []
|
|
64
91
|
require_paths:
|
|
65
92
|
- lib
|
|
@@ -67,25 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
67
94
|
requirements:
|
|
68
95
|
- - ">="
|
|
69
96
|
- !ruby/object:Gem::Version
|
|
70
|
-
version:
|
|
97
|
+
version: 3.2.0
|
|
71
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
99
|
requirements:
|
|
73
100
|
- - ">="
|
|
74
101
|
- !ruby/object:Gem::Version
|
|
75
102
|
version: '0'
|
|
76
103
|
requirements: []
|
|
77
|
-
|
|
78
|
-
rubygems_version: 2.2.3
|
|
79
|
-
signing_key:
|
|
104
|
+
rubygems_version: 3.6.9
|
|
80
105
|
specification_version: 4
|
|
81
106
|
summary: Encode/decode HTML entities
|
|
82
|
-
test_files:
|
|
83
|
-
- test/interoperability_test.rb
|
|
84
|
-
- test/encoding_test.rb
|
|
85
|
-
- test/string_encodings_test.rb
|
|
86
|
-
- test/entities_test.rb
|
|
87
|
-
- test/html4_test.rb
|
|
88
|
-
- test/xhtml1_test.rb
|
|
89
|
-
- test/expanded_test.rb
|
|
90
|
-
- test/decoding_test.rb
|
|
91
|
-
- test/roundtrip_test.rb
|
|
107
|
+
test_files: []
|
data/perf/benchmark.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
$KCODE = 'u' unless "1.9".respond_to?(:encoding)
|
|
3
|
-
|
|
4
|
-
require File.expand_path("../performance", __FILE__)
|
|
5
|
-
require "benchmark"
|
|
6
|
-
|
|
7
|
-
job = HTMLEntitiesJob.new
|
|
8
|
-
job.all(100) # Warm up to give JRuby a fair shake.
|
|
9
|
-
|
|
10
|
-
Benchmark.benchmark do |b|
|
|
11
|
-
b.report("Encoding"){ job.encode(100) }
|
|
12
|
-
b.report("Decoding"){ job.decode(100) }
|
|
13
|
-
end
|
data/perf/performance.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
$KCODE = 'u' unless "1.9".respond_to?(:encoding)
|
|
3
|
-
|
|
4
|
-
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
5
|
-
require "htmlentities"
|
|
6
|
-
|
|
7
|
-
class HTMLEntitiesJob
|
|
8
|
-
def initialize
|
|
9
|
-
@coder = HTMLEntities.new
|
|
10
|
-
@decoded = File.read(File.join(File.dirname(__FILE__), "sample"))
|
|
11
|
-
@encoded = @coder.encode(@decoded, :basic, :named, :hexadecimal)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def encode(cycles)
|
|
15
|
-
cycles.times do
|
|
16
|
-
@coder.encode(@decoded, :basic, :named, :hexadecimal)
|
|
17
|
-
@coder.encode(@decoded, :basic, :named, :decimal)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def decode(cycles)
|
|
22
|
-
cycles.times do
|
|
23
|
-
@coder.decode(@encoded)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def all(cycles)
|
|
28
|
-
encode(cycles)
|
|
29
|
-
decode(cycles)
|
|
30
|
-
end
|
|
31
|
-
end
|
data/perf/profile.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
$KCODE = 'u' unless "1.9".respond_to?(:encoding)
|
|
3
|
-
|
|
4
|
-
require File.expand_path("../performance", __FILE__)
|
|
5
|
-
require "profiler"
|
|
6
|
-
|
|
7
|
-
job = HTMLEntitiesJob.new
|
|
8
|
-
|
|
9
|
-
puts "Encoding"
|
|
10
|
-
Profiler__::start_profile
|
|
11
|
-
job.encode(1)
|
|
12
|
-
Profiler__::print_profile($stdout)
|
|
13
|
-
|
|
14
|
-
puts "Decoding"
|
|
15
|
-
Profiler__::start_profile
|
|
16
|
-
job.decode(1)
|
|
17
|
-
Profiler__::print_profile($stdout)
|
data/test/decoding_test.rb
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative "./test_helper"
|
|
3
|
-
|
|
4
|
-
class HTMLEntities::DecodingTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
@entities = [:xhtml1, :html4, :expanded].map{ |a| HTMLEntities.new(a) }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def assert_decode(expected, input)
|
|
11
|
-
@entities.each do |coder|
|
|
12
|
-
assert_equal expected, coder.decode(input)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_decode_basic_entities
|
|
17
|
-
assert_decode '&', '&'
|
|
18
|
-
assert_decode '<', '<'
|
|
19
|
-
assert_decode '"', '"'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def test_should_decode_extended_named_entities
|
|
23
|
-
assert_decode '±', '±'
|
|
24
|
-
assert_decode 'ð', 'ð'
|
|
25
|
-
assert_decode 'Œ', 'Œ'
|
|
26
|
-
assert_decode 'œ', 'œ'
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_should_decode_decimal_entities
|
|
30
|
-
assert_decode '“', '“'
|
|
31
|
-
assert_decode '…', '…'
|
|
32
|
-
assert_decode ' ', ' '
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_should_decode_hexadecimal_entities
|
|
36
|
-
assert_decode '−', '−'
|
|
37
|
-
assert_decode '—', '—'
|
|
38
|
-
assert_decode '`', '`'
|
|
39
|
-
assert_decode '`', '`'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_should_not_mutate_string_being_decoded
|
|
43
|
-
original = "<£"
|
|
44
|
-
input = original.dup
|
|
45
|
-
HTMLEntities.new.decode(input)
|
|
46
|
-
|
|
47
|
-
assert_equal original, input
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_should_decode_text_with_mix_of_entities
|
|
51
|
-
# Just a random headline - I needed something with accented letters.
|
|
52
|
-
assert_decode(
|
|
53
|
-
'Le tabac pourrait bientôt être banni dans tous les lieux publics en France',
|
|
54
|
-
'Le tabac pourrait bientôt être banni dans tous les lieux publics en France'
|
|
55
|
-
)
|
|
56
|
-
assert_decode(
|
|
57
|
-
'"bientôt" & 文字',
|
|
58
|
-
'"bientôt" & 文字'
|
|
59
|
-
)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_should_decode_empty_string
|
|
63
|
-
assert_decode '', ''
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_should_skip_unknown_entity
|
|
67
|
-
assert_decode '&bogus;', '&bogus;'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_should_decode_double_encoded_entity_once
|
|
71
|
-
assert_decode '&', '&amp;'
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Faults found and patched by Moonwolf
|
|
75
|
-
def test_should_decode_full_hexadecimal_range
|
|
76
|
-
(0..127).each do |codepoint|
|
|
77
|
-
assert_decode [codepoint].pack('U'), "&\#x#{codepoint.to_s(16)};"
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Reported by Dallas DeVries and Johan Duflost
|
|
82
|
-
def test_should_decode_named_entities_reported_as_missing_in_3_0_1
|
|
83
|
-
assert_decode [178].pack('U'), '²'
|
|
84
|
-
assert_decode [8226].pack('U'), '•'
|
|
85
|
-
assert_decode [948].pack('U'), 'δ'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Reported by ckruse
|
|
89
|
-
def test_should_decode_only_first_element_in_masked_entities
|
|
90
|
-
input = '&#3346;'
|
|
91
|
-
expected = 'ഒ'
|
|
92
|
-
assert_decode expected, input
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def test_should_ducktype_parameter_to_string_before_encoding
|
|
96
|
-
obj = Object.new
|
|
97
|
-
def obj.to_s; "foo"; end
|
|
98
|
-
assert_decode "foo", obj
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
end
|
data/test/encoding_test.rb
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative "./test_helper"
|
|
3
|
-
|
|
4
|
-
class HTMLEntities::EncodingTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
@entities = [:xhtml1, :html4, :expanded].map{ |a| HTMLEntities.new(a) }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def assert_encode(expected, input, *args)
|
|
11
|
-
@entities.each do |coder|
|
|
12
|
-
assert_equal expected, coder.encode(input, *args)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_encode_basic_entities
|
|
17
|
-
assert_encode '&', '&', :basic
|
|
18
|
-
assert_encode '"', '"'
|
|
19
|
-
assert_encode '<', '<', :basic
|
|
20
|
-
assert_encode '<', '<'
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_should_encode_basic_entities_to_decimal
|
|
24
|
-
assert_encode '&', '&', :decimal
|
|
25
|
-
assert_encode '"', '"', :decimal
|
|
26
|
-
assert_encode '<', '<', :decimal
|
|
27
|
-
assert_encode '>', '>', :decimal
|
|
28
|
-
assert_encode ''', "'", :decimal
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_should_encode_basic_entities_to_hexadecimal
|
|
32
|
-
assert_encode '&', '&', :hexadecimal
|
|
33
|
-
assert_encode '"', '"', :hexadecimal
|
|
34
|
-
assert_encode '<', '<', :hexadecimal
|
|
35
|
-
assert_encode '>', '>', :hexadecimal
|
|
36
|
-
assert_encode ''', "'", :hexadecimal
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_should_encode_extended_named_entities
|
|
40
|
-
assert_encode '±', '±', :named
|
|
41
|
-
assert_encode 'ð', 'ð', :named
|
|
42
|
-
assert_encode 'Œ', 'Œ', :named
|
|
43
|
-
assert_encode 'œ', 'œ', :named
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_should_encode_decimal_entities
|
|
47
|
-
assert_encode '“', '“', :decimal
|
|
48
|
-
assert_encode '…', '…', :decimal
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_should_encode_hexadecimal_entities
|
|
52
|
-
assert_encode '−', '−', :hexadecimal
|
|
53
|
-
assert_encode '—', '—', :hexadecimal
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_should_encode_text_using_mix_of_entities
|
|
57
|
-
assert_encode(
|
|
58
|
-
'"bientôt" & 文字',
|
|
59
|
-
'"bientôt" & 文字', :basic, :named, :hexadecimal
|
|
60
|
-
)
|
|
61
|
-
assert_encode(
|
|
62
|
-
'"bientôt" & 文字',
|
|
63
|
-
'"bientôt" & 文字', :basic, :named, :decimal
|
|
64
|
-
)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_should_sort_commands_when_encoding_using_mix_of_entities
|
|
68
|
-
assert_encode(
|
|
69
|
-
'"bientôt" & 文字',
|
|
70
|
-
'"bientôt" & 文字', :named, :hexadecimal, :basic
|
|
71
|
-
)
|
|
72
|
-
assert_encode(
|
|
73
|
-
'"bientôt" & 文字',
|
|
74
|
-
'"bientôt" & 文字', :decimal, :named, :basic
|
|
75
|
-
)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_should_detect_illegal_encoding_command
|
|
79
|
-
assert_raise HTMLEntities::InstructionError do
|
|
80
|
-
HTMLEntities.new.encode('foo', :bar, :baz)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def test_should_not_encode_normal_ASCII
|
|
85
|
-
assert_encode '`', '`'
|
|
86
|
-
assert_encode ' ', ' '
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_should_double_encode_existing_entity
|
|
90
|
-
assert_encode '&amp;', '&'
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def test_should_not_mutate_string_being_encoded
|
|
94
|
-
original = "<£"
|
|
95
|
-
input = original.dup
|
|
96
|
-
HTMLEntities.new.encode(input, :basic, :decimal)
|
|
97
|
-
|
|
98
|
-
assert_equal original, input
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_should_ducktype_parameter_to_string_before_encoding
|
|
102
|
-
obj = Object.new
|
|
103
|
-
def obj.to_s; "foo"; end
|
|
104
|
-
assert_encode "foo", obj
|
|
105
|
-
end
|
|
106
|
-
end
|
data/test/entities_test.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative "./test_helper"
|
|
3
|
-
|
|
4
|
-
class HTMLEntities::EntitiesTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def test_should_raise_exception_when_unknown_flavor_specified
|
|
7
|
-
assert_raises HTMLEntities::UnknownFlavor do
|
|
8
|
-
HTMLEntities.new('foo')
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_should_allow_symbol_for_flavor
|
|
13
|
-
assert_nothing_raised do
|
|
14
|
-
HTMLEntities.new(:xhtml1)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def test_should_allow_upper_case_flavor
|
|
19
|
-
assert_nothing_raised do
|
|
20
|
-
HTMLEntities.new('XHTML1')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|
data/test/expanded_test.rb
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative "./test_helper"
|
|
3
|
-
|
|
4
|
-
class HTMLEntities::ExpandedTest < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
attr_reader :html_entities
|
|
7
|
-
|
|
8
|
-
def setup
|
|
9
|
-
@html_entities = HTMLEntities.new(:expanded)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
TEST_ENTITIES_SET = [
|
|
13
|
-
['sub', 0x2282, "xhtml", nil, "⊂", ],
|
|
14
|
-
['sup', 0x2283, "xhtml", nil, "⊃", ],
|
|
15
|
-
['nsub', 0x2284, "xhtml", nil, "⊄", ],
|
|
16
|
-
['subE', 0x2286, nil, "skip", "⊆", ],
|
|
17
|
-
['sube', 0x2286, "xhtml", nil, "⊆", ],
|
|
18
|
-
['supE', 0x2287, nil, "skip", "⊇", ],
|
|
19
|
-
['supe', 0x2287, "xhtml", nil, "⊇", ],
|
|
20
|
-
['bottom', 0x22a5, nil, "skip", "⊥", ],
|
|
21
|
-
['perp', 0x22a5, "xhtml", nil, "⊥", ],
|
|
22
|
-
['models', 0x22a7, nil, nil, "⊧", ],
|
|
23
|
-
['vDash', 0x22a8, nil, nil, "⊨", ],
|
|
24
|
-
['Vdash', 0x22a9, nil, nil, "⊩", ],
|
|
25
|
-
['Vvdash', 0x22aa, nil, nil, "⊪", ],
|
|
26
|
-
['nvdash', 0x22ac, nil, nil, "⊬", ],
|
|
27
|
-
['nvDash', 0x22ad, nil, nil, "⊭", ],
|
|
28
|
-
['nVdash', 0x22ae, nil, nil, "⊮", ],
|
|
29
|
-
['nsubE', 0x2288, nil, nil, "⊈", ],
|
|
30
|
-
['nsube', 0x2288, nil, "skip", "⊈", ],
|
|
31
|
-
['nsupE', 0x2289, nil, nil, "⊉", ],
|
|
32
|
-
['nsupe', 0x2289, nil, "skip", "⊉", ],
|
|
33
|
-
['subnE', 0x228a, nil, nil, "⊊", ],
|
|
34
|
-
['subne', 0x228a, nil, "skip", "⊊", ],
|
|
35
|
-
['vsubnE', 0x228a, nil, "skip", "⊊", ],
|
|
36
|
-
['vsubne', 0x228a, nil, "skip", "⊊", ],
|
|
37
|
-
['nsc', 0x2281, nil, nil, "⊁", ],
|
|
38
|
-
['nsup', 0x2285, nil, nil, "⊅", ],
|
|
39
|
-
['b.alpha', 0x03b1, nil, "skip", "α", ],
|
|
40
|
-
['b.beta', 0x03b2, nil, "skip", "β", ],
|
|
41
|
-
['b.chi', 0x03c7, nil, "skip", "χ", ],
|
|
42
|
-
['b.Delta', 0x0394, nil, "skip", "Δ", ],
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
def test_should_encode_apos_entity
|
|
46
|
-
assert_equal "'", html_entities.encode("'", :named) # note: the normal ' 0x0027, not ʼ 0x02BC
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_should_decode_apos_entity
|
|
50
|
-
assert_equal "é'", html_entities.decode("é'")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def test_should_decode_dotted_entity
|
|
54
|
-
assert_equal "Θ", html_entities.decode("&b.Theta;")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_should_encode_from_test_set
|
|
58
|
-
TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
|
|
59
|
-
next if skip
|
|
60
|
-
assert_equal "&#{ent};", html_entities.encode(decoded, :named)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_should_decode_from_test_set
|
|
65
|
-
TEST_ENTITIES_SET.each do |ent, _, _, _, decoded|
|
|
66
|
-
assert_equal decoded, html_entities.decode("&#{ent};")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_should_round_trip_preferred_entities
|
|
71
|
-
TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
|
|
72
|
-
next if skip
|
|
73
|
-
assert_equal "&#{ent};", html_entities.encode(html_entities.decode("&#{ent};"), :named)
|
|
74
|
-
assert_equal decoded, html_entities.decode(html_entities.encode(decoded, :named))
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_should_not_round_trip_decoding_skipped_entities
|
|
79
|
-
TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
|
|
80
|
-
next unless skip
|
|
81
|
-
assert_not_equal "&#{ent};", html_entities.encode(html_entities.decode("&#{ent};"), :named)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def test_should_round_trip_encoding_skipped_entities
|
|
86
|
-
TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
|
|
87
|
-
next unless skip
|
|
88
|
-
assert_equal decoded, html_entities.decode(html_entities.encode(decoded, :named))
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_should_treat_all_xhtml1_named_entities_as_xhtml_does
|
|
93
|
-
xhtml_encoder = HTMLEntities.new(:xhtml1)
|
|
94
|
-
HTMLEntities::MAPPINGS['xhtml1'].each do |ent, decoded|
|
|
95
|
-
assert_equal xhtml_encoder.decode("&#{ent};"), html_entities.decode("&#{ent};")
|
|
96
|
-
assert_equal xhtml_encoder.encode(decoded, :named), html_entities.encode(decoded, :named)
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_should_not_agree_with_xhtml1_when_not_in_xhtml
|
|
101
|
-
xhtml_encoder = HTMLEntities.new(:xhtml1)
|
|
102
|
-
TEST_ENTITIES_SET.each do |ent, _, xhtml1, skip, decoded|
|
|
103
|
-
next if xhtml1 || skip
|
|
104
|
-
assert_not_equal xhtml_encoder.decode("&#{ent};"), html_entities.decode("&#{ent};")
|
|
105
|
-
assert_not_equal xhtml_encoder.encode(decoded, :named), html_entities.encode(decoded, :named)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
end
|
data/test/html4_test.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
data/test/roundtrip_test.rb
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
|
@@ -1,68 +0,0 @@
|
|
|
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
DELETED
data/test/xhtml1_test.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|