htmlentities 4.0.0 → 4.1.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.
@@ -1,5 +1,5 @@
1
+ # encoding: UTF-8
1
2
  class HTMLEntities
2
- MAPPINGS = {} unless defined? MAPPINGS
3
3
  MAPPINGS['html4'] = {
4
4
  'Aacute' => 193,
5
5
  'aacute' => 225,
@@ -1,5 +1,5 @@
1
+ # encoding: UTF-8
1
2
  class HTMLEntities
2
- MAPPINGS = {} unless defined? MAPPINGS
3
3
  MAPPINGS['xhtml1'] = {
4
4
  'Aacute' => 193,
5
5
  'aacute' => 225,
@@ -0,0 +1,9 @@
1
+ class HTMLEntities #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 4
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'htmlentities'
3
3
  require 'test/unit'
4
+ require 'htmlentities'
4
5
 
5
- $KCODE = 'u'
6
+ $KCODE = 'u' unless "1.9".respond_to?(:encoding)
6
7
 
7
8
  class HTMLEntities::EntitiesTest < Test::Unit::TestCase
8
9
 
@@ -21,7 +22,7 @@ class HTMLEntities::EntitiesTest < Test::Unit::TestCase
21
22
  @string
22
23
  end
23
24
  end
24
-
25
+
25
26
  def test_should_raise_exception_when_unknown_flavor_specified
26
27
  assert_raises(HTMLEntities::UnknownFlavor) do
27
28
  HTMLEntities.new('foo')
@@ -52,7 +53,7 @@ class HTMLEntities::EntitiesTest < Test::Unit::TestCase
52
53
  assert_encode('&lt;', '<', :basic)
53
54
  assert_encode('&lt;', '<')
54
55
  end
55
-
56
+
56
57
  def test_should_encode_basic_entities_to_decimal
57
58
  assert_encode('&#38;', '&', :decimal)
58
59
  assert_encode('&#34;', '"', :decimal)
@@ -0,0 +1,112 @@
1
+ # encoding: UTF-8
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+ require 'test/unit'
4
+ require 'htmlentities'
5
+
6
+ $KCODE = 'u' unless "1.9".respond_to?(:encoding)
7
+
8
+ class HTMLEntities::ExpandedTest < Test::Unit::TestCase
9
+
10
+ attr_reader :html_entities
11
+
12
+ def setup
13
+ @html_entities = HTMLEntities.new(:expanded)
14
+ end
15
+
16
+ TEST_ENTITIES_SET = [
17
+ ['sub', 0x2282, "xhtml", nil, "⊂", ],
18
+ ['sup', 0x2283, "xhtml", nil, "⊃", ],
19
+ ['nsub', 0x2284, "xhtml", nil, "⊄", ],
20
+ ['subE', 0x2286, nil, "skip", "⊆", ],
21
+ ['sube', 0x2286, "xhtml", nil, "⊆", ],
22
+ ['supE', 0x2287, nil, "skip", "⊇", ],
23
+ ['supe', 0x2287, "xhtml", nil, "⊇", ],
24
+ ['bottom', 0x22a5, nil, "skip", "⊥", ],
25
+ ['perp', 0x22a5, "xhtml", nil, "⊥", ],
26
+ ['models', 0x22a7, nil, nil, "⊧", ],
27
+ ['vDash', 0x22a8, nil, nil, "⊨", ],
28
+ ['Vdash', 0x22a9, nil, nil, "⊩", ],
29
+ ['Vvdash', 0x22aa, nil, nil, "⊪", ],
30
+ ['nvdash', 0x22ac, nil, nil, "⊬", ],
31
+ ['nvDash', 0x22ad, nil, nil, "⊭", ],
32
+ ['nVdash', 0x22ae, nil, nil, "⊮", ],
33
+ ['nsubE', 0x2288, nil, nil, "⊈", ],
34
+ ['nsube', 0x2288, nil, "skip", "⊈", ],
35
+ ['nsupE', 0x2289, nil, nil, "⊉", ],
36
+ ['nsupe', 0x2289, nil, "skip", "⊉", ],
37
+ ['subnE', 0x228a, nil, nil, "⊊", ],
38
+ ['subne', 0x228a, nil, "skip", "⊊", ],
39
+ ['vsubnE', 0x228a, nil, "skip", "⊊", ],
40
+ ['vsubne', 0x228a, nil, "skip", "⊊", ],
41
+ ['nsc', 0x2281, nil, nil, "⊁", ],
42
+ ['nsup', 0x2285, nil, nil, "⊅", ],
43
+ ['b.alpha', 0x03b1, nil, "skip", "α", ],
44
+ ['b.beta', 0x03b2, nil, "skip", "β", ],
45
+ ['b.chi', 0x03c7, nil, "skip", "χ", ],
46
+ ['b.Delta', 0x0394, nil, "skip", "Δ", ],
47
+ ]
48
+
49
+ def test_should_encode_apos_entity
50
+ assert_equal "&apos;", html_entities.encode("'", :named) # note: the normal ' 0x0027, not ʼ 0x02BC
51
+ end
52
+
53
+ def test_should_decode_apos_entity
54
+ assert_equal "é'", html_entities.decode("&eacute;&apos;")
55
+ end
56
+
57
+ def test_should_decode_dotted_entity
58
+ assert_equal "Θ", html_entities.decode("&b.Theta;")
59
+ end
60
+
61
+ def test_should_encode_from_test_set
62
+ TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
63
+ next if skip
64
+ assert_equal "&#{ent};", html_entities.encode(decoded, :named)
65
+ end
66
+ end
67
+
68
+ def test_should_decode_from_test_set
69
+ TEST_ENTITIES_SET.each do |ent, _, _, _, decoded|
70
+ assert_equal decoded, html_entities.decode("&#{ent};")
71
+ end
72
+ end
73
+
74
+ def test_should_round_trip_preferred_entities
75
+ TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
76
+ next if skip
77
+ assert_equal "&#{ent};", html_entities.encode(html_entities.decode("&#{ent};"), :named)
78
+ assert_equal decoded, html_entities.decode(html_entities.encode(decoded, :named))
79
+ end
80
+ end
81
+
82
+ def test_should_not_round_trip_decoding_skipped_entities
83
+ TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
84
+ next unless skip
85
+ assert_not_equal "&#{ent};", html_entities.encode(html_entities.decode("&#{ent};"), :named)
86
+ end
87
+ end
88
+
89
+ def test_should_round_trip_encoding_skipped_entities
90
+ TEST_ENTITIES_SET.each do |ent, _, _, skip, decoded|
91
+ next unless skip
92
+ assert_equal decoded, html_entities.decode(html_entities.encode(decoded, :named))
93
+ end
94
+ end
95
+
96
+ def test_should_treat_all_xhtml1_named_entities_as_xhtml_does
97
+ xhtml_encoder = HTMLEntities.new(:xhtml1)
98
+ HTMLEntities::MAPPINGS['xhtml1'].each do |ent, decoded|
99
+ assert_equal xhtml_encoder.decode("&#{ent};"), html_entities.decode("&#{ent};")
100
+ assert_equal xhtml_encoder.encode(decoded, :named), html_entities.encode(decoded, :named)
101
+ end
102
+ end
103
+
104
+ def test_should_not_agree_with_xhtml1_when_not_in_xhtml
105
+ xhtml_encoder = HTMLEntities.new(:xhtml1)
106
+ TEST_ENTITIES_SET.each do |ent, _, xhtml1, skip, decoded|
107
+ next if xhtml1 || skip
108
+ assert_not_equal xhtml_encoder.decode("&#{ent};"), html_entities.decode("&#{ent};")
109
+ assert_not_equal xhtml_encoder.encode(decoded, :named), html_entities.encode(decoded, :named)
110
+ end
111
+ end
112
+ end
data/test/html4_test.rb CHANGED
@@ -1,10 +1,11 @@
1
+ # encoding: UTF-8
1
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'htmlentities'
3
3
  require 'test/unit'
4
+ require 'htmlentities'
4
5
 
5
- $KCODE = 'u'
6
+ $KCODE = 'u' unless "1.9".respond_to?(:encoding)
6
7
 
7
- class HTMLEntities::HTML4Test < Test::Unit::TestCase
8
+ class HTML4Test < Test::Unit::TestCase
8
9
 
9
10
  attr_reader :html_entities
10
11
 
@@ -21,4 +22,8 @@ class HTMLEntities::HTML4Test < Test::Unit::TestCase
21
22
  assert_equal "é&apos;", html_entities.decode("&eacute;&apos;")
22
23
  end
23
24
 
25
+ def test_should_not_decode_dotted_entity
26
+ assert_equal "&b.Theta;", html_entities.decode("&b.Theta;")
27
+ end
28
+
24
29
  end
data/test/legacy_test.rb CHANGED
@@ -1,14 +1,15 @@
1
+ # encoding: UTF-8
1
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'htmlentities'
3
3
  require 'test/unit'
4
+ require 'htmlentities'
4
5
 
5
- $KCODE = 'u'
6
+ $KCODE = 'u' unless "1.9".respond_to?(:encoding)
6
7
 
7
8
  #
8
9
  # Test that version 3.x functionality still works
9
10
  #
10
11
  class HTMLEntities::LegacyTest < Test::Unit::TestCase
11
-
12
+
12
13
  def test_should_decode_via_legacy_interface
13
14
  assert_decode('&', '&amp;')
14
15
  assert_decode('±', '&plusmn;')
@@ -22,7 +23,7 @@ class HTMLEntities::LegacyTest < Test::Unit::TestCase
22
23
  assert_encode('&#8230;', '…', :decimal)
23
24
  assert_encode('&#x2212;', '−', :hexadecimal)
24
25
  end
25
-
26
+
26
27
  def assert_encode(expected, *encode_args)
27
28
  assert_equal expected, HTMLEntities.encode_entities(*encode_args)
28
29
  end
@@ -30,5 +31,5 @@ class HTMLEntities::LegacyTest < Test::Unit::TestCase
30
31
  def assert_decode(expected, *decode_args)
31
32
  assert_equal expected, HTMLEntities.decode_entities(*decode_args)
32
33
  end
33
-
34
- end
34
+
35
+ end
@@ -1,22 +1,21 @@
1
+ # encoding: UTF-8
1
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'htmlentities'
3
3
  require 'test/unit'
4
- require 'htmlentities/xhtml1'
5
- require 'htmlentities/html4'
4
+ require 'htmlentities'
6
5
 
7
6
  class HTMLEntities::RoundtripTest < Test::Unit::TestCase
8
-
7
+
9
8
  attr_reader :xhtml1_entities, :html4_entities
10
-
9
+
11
10
  def setup
12
11
  @xhtml1_entities = HTMLEntities.new('xhtml1')
13
12
  @html4_entities = HTMLEntities.new('html4')
14
13
  end
15
-
14
+
16
15
  def test_should_roundtrip_xhtml1_entities_via_named_encoding
17
16
  each_mapping('xhtml1') do |name, string|
18
17
  assert_equal(
19
- string,
18
+ string,
20
19
  xhtml1_entities.decode(xhtml1_entities.encode(string, :named))
21
20
  )
22
21
  end
@@ -25,34 +24,34 @@ class HTMLEntities::RoundtripTest < Test::Unit::TestCase
25
24
  def test_should_roundtrip_xhtml1_entities_via_basic_and_named_encoding
26
25
  each_mapping('xhtml1') do |name, string|
27
26
  assert_equal(
28
- string,
27
+ string,
29
28
  xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named))
30
29
  )
31
30
  end
32
31
  end
33
-
32
+
34
33
  def test_should_roundtrip_xhtml1_entities_via_basic_named_and_decimal_encoding
35
34
  each_mapping('xhtml1') do |name, string|
36
35
  assert_equal(
37
- string,
36
+ string,
38
37
  xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named, :decimal))
39
38
  )
40
39
  end
41
40
  end
42
-
41
+
43
42
  def test_should_roundtrip_xhtml1_entities_via_hexadecimal_encoding
44
43
  each_mapping('xhtml1') do |name, string|
45
44
  assert_equal(
46
- string,
45
+ string,
47
46
  xhtml1_entities.decode(xhtml1_entities.encode(string, :hexadecimal))
48
47
  )
49
48
  end
50
49
  end
51
-
50
+
52
51
  def test_should_roundtrip_html4_entities_via_named_encoding
53
52
  each_mapping('html4') do |name, string|
54
53
  assert_equal(
55
- string,
54
+ string,
56
55
  html4_entities.decode(html4_entities.encode(string, :named))
57
56
  )
58
57
  end
@@ -61,34 +60,34 @@ class HTMLEntities::RoundtripTest < Test::Unit::TestCase
61
60
  def test_should_roundtrip_html4_entities_via_basic_and_named_encoding
62
61
  each_mapping('html4') do |name, string|
63
62
  assert_equal(
64
- string,
63
+ string,
65
64
  html4_entities.decode(html4_entities.encode(string, :basic, :named))
66
65
  )
67
66
  end
68
67
  end
69
-
68
+
70
69
  def test_should_roundtrip_html4_entities_via_basic_named_and_decimal_encoding
71
70
  each_mapping('html4') do |name, string|
72
71
  assert_equal(
73
- string,
72
+ string,
74
73
  html4_entities.decode(html4_entities.encode(string, :basic, :named, :decimal))
75
74
  )
76
75
  end
77
76
  end
78
-
77
+
79
78
  def test_should_roundtrip_html4_entities_via_hexadecimal_encoding
80
79
  each_mapping('html4') do |name, string|
81
80
  assert_equal(
82
- string,
81
+ string,
83
82
  html4_entities.decode(html4_entities.encode(string, :hexadecimal))
84
83
  )
85
84
  end
86
85
  end
87
-
86
+
88
87
  def each_mapping(flavor)
89
88
  HTMLEntities::MAPPINGS[flavor].each do |name, codepoint|
90
89
  yield name, [codepoint].pack('U')
91
90
  end
92
91
  end
93
-
94
- end
92
+
93
+ end
data/test/test_all.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  Dir[File.dirname(__FILE__)+'/*_test.rb'].each do |test|
2
3
  require test
3
- end
4
+ end
data/test/xhtml1_test.rb CHANGED
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- require 'htmlentities'
3
3
  require 'test/unit'
4
+ require 'htmlentities'
4
5
 
5
- $KCODE = 'u'
6
+ $KCODE = 'u' unless "1.9".respond_to?(:encoding)
6
7
 
7
8
  class HTMLEntities::XHTML1Test < Test::Unit::TestCase
8
9
 
@@ -20,4 +21,9 @@ class HTMLEntities::XHTML1Test < Test::Unit::TestCase
20
21
  assert_equal "é'", html_entities.decode("&eacute;&apos;")
21
22
  end
22
23
 
24
+ def test_should_not_decode_dotted_entity
25
+ assert_equal "&b.Theta;", html_entities.decode("&b.Theta;")
26
+ end
27
+
28
+
23
29
  end
metadata CHANGED
@@ -1,62 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.1
3
- specification_version: 1
4
2
  name: htmlentities
5
3
  version: !ruby/object:Gem::Version
6
- version: 4.0.0
7
- date: 2007-03-15 00:00:00 +00:00
8
- summary: A module for encoding and decoding (X)HTML entities.
9
- require_paths:
10
- - lib
11
- email: pbattley@gmail.com
12
- homepage: http://htmlentities.rubyforge.org/
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 4.1.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Paul Battley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: pbattley@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ - History.txt
25
+ - COPYING.txt
31
26
  files:
32
- - lib/htmlentities.rb
33
- - lib/htmlentities/html4.rb
27
+ - lib/htmlentities/mappings/html4.rb
28
+ - lib/htmlentities/mappings/expanded.rb
29
+ - lib/htmlentities/mappings/xhtml1.rb
30
+ - lib/htmlentities/flavors.rb
34
31
  - lib/htmlentities/legacy.rb
35
- - lib/htmlentities/string.rb
36
- - lib/htmlentities/xhtml1.rb
37
- - test/entities_test.rb
32
+ - lib/htmlentities/version.rb
33
+ - lib/htmlentities.rb
38
34
  - test/html4_test.rb
39
- - test/legacy_test.rb
40
- - test/roundtrip_test.rb
41
- - test/string_test.rb
42
35
  - test/test_all.rb
43
36
  - test/xhtml1_test.rb
37
+ - test/roundtrip_test.rb
38
+ - test/expanded_test.rb
39
+ - test/legacy_test.rb
40
+ - test/entities_test.rb
44
41
  - README.txt
45
42
  - History.txt
46
43
  - COPYING.txt
47
- test_files:
48
- - test/test_all.rb
44
+ has_rdoc: true
45
+ homepage: http://htmlentities.rubyforge.org/
46
+ post_install_message:
49
47
  rdoc_options: []
50
48
 
51
- extra_rdoc_files:
52
- - README.txt
53
- - History.txt
54
- - COPYING.txt
55
- executables: []
56
-
57
- extensions: []
58
-
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
59
63
  requirements: []
60
64
 
61
- dependencies: []
62
-
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: A module for encoding and decoding (X)HTML entities.
70
+ test_files:
71
+ - test/test_all.rb