htmlentities 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'htmlentities'
3
+ require 'test/unit'
4
+
5
+ $KCODE = 'u'
6
+
7
+ class HTMLEntities::HTML4Test < Test::Unit::TestCase
8
+
9
+ attr_reader :html_entities
10
+
11
+ def setup
12
+ @html_entities = HTMLEntities.new('html4')
13
+ end
14
+
15
+ # Found by Marcos Kuhns
16
+ def test_should_not_encode_apos_entity
17
+ assert_equal "'", html_entities.encode("'", :basic)
18
+ end
19
+
20
+ def test_should_not_decode_apos_entity
21
+ assert_equal "é&apos;", html_entities.decode("&eacute;&apos;")
22
+ end
23
+
24
+ end
@@ -0,0 +1,34 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'htmlentities'
3
+ require 'test/unit'
4
+
5
+ $KCODE = 'u'
6
+
7
+ #
8
+ # Test that version 3.x functionality still works
9
+ #
10
+ class HTMLEntities::LegacyTest < Test::Unit::TestCase
11
+
12
+ def test_should_decode_via_legacy_interface
13
+ assert_decode('&', '&amp;')
14
+ assert_decode('±', '&plusmn;')
15
+ assert_decode('“', '&#8220;')
16
+ assert_decode('—', '&#x2014;')
17
+ end
18
+
19
+ def test_should_encode_via_legacy_interface
20
+ assert_encode('&amp;', '&', :basic)
21
+ assert_encode('&eth;', 'ð', :named)
22
+ assert_encode('&#8230;', '…', :decimal)
23
+ assert_encode('&#x2212;', '−', :hexadecimal)
24
+ end
25
+
26
+ def assert_encode(expected, *encode_args)
27
+ assert_equal expected, HTMLEntities.encode_entities(*encode_args)
28
+ end
29
+
30
+ def assert_decode(expected, *decode_args)
31
+ assert_equal expected, HTMLEntities.decode_entities(*decode_args)
32
+ end
33
+
34
+ end
@@ -0,0 +1,94 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'htmlentities'
3
+ require 'test/unit'
4
+ require 'htmlentities/xhtml1'
5
+ require 'htmlentities/html4'
6
+
7
+ class HTMLEntities::RoundtripTest < Test::Unit::TestCase
8
+
9
+ attr_reader :xhtml1_entities, :html4_entities
10
+
11
+ def setup
12
+ @xhtml1_entities = HTMLEntities.new('xhtml1')
13
+ @html4_entities = HTMLEntities.new('html4')
14
+ end
15
+
16
+ def test_should_roundtrip_xhtml1_entities_via_named_encoding
17
+ each_mapping('xhtml1') do |name, string|
18
+ assert_equal(
19
+ string,
20
+ xhtml1_entities.decode(xhtml1_entities.encode(string, :named))
21
+ )
22
+ end
23
+ end
24
+
25
+ def test_should_roundtrip_xhtml1_entities_via_basic_and_named_encoding
26
+ each_mapping('xhtml1') do |name, string|
27
+ assert_equal(
28
+ string,
29
+ xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named))
30
+ )
31
+ end
32
+ end
33
+
34
+ def test_should_roundtrip_xhtml1_entities_via_basic_named_and_decimal_encoding
35
+ each_mapping('xhtml1') do |name, string|
36
+ assert_equal(
37
+ string,
38
+ xhtml1_entities.decode(xhtml1_entities.encode(string, :basic, :named, :decimal))
39
+ )
40
+ end
41
+ end
42
+
43
+ def test_should_roundtrip_xhtml1_entities_via_hexadecimal_encoding
44
+ each_mapping('xhtml1') do |name, string|
45
+ assert_equal(
46
+ string,
47
+ xhtml1_entities.decode(xhtml1_entities.encode(string, :hexadecimal))
48
+ )
49
+ end
50
+ end
51
+
52
+ def test_should_roundtrip_html4_entities_via_named_encoding
53
+ each_mapping('html4') do |name, string|
54
+ assert_equal(
55
+ string,
56
+ html4_entities.decode(html4_entities.encode(string, :named))
57
+ )
58
+ end
59
+ end
60
+
61
+ def test_should_roundtrip_html4_entities_via_basic_and_named_encoding
62
+ each_mapping('html4') do |name, string|
63
+ assert_equal(
64
+ string,
65
+ html4_entities.decode(html4_entities.encode(string, :basic, :named))
66
+ )
67
+ end
68
+ end
69
+
70
+ def test_should_roundtrip_html4_entities_via_basic_named_and_decimal_encoding
71
+ each_mapping('html4') do |name, string|
72
+ assert_equal(
73
+ string,
74
+ html4_entities.decode(html4_entities.encode(string, :basic, :named, :decimal))
75
+ )
76
+ end
77
+ end
78
+
79
+ def test_should_roundtrip_html4_entities_via_hexadecimal_encoding
80
+ each_mapping('html4') do |name, string|
81
+ assert_equal(
82
+ string,
83
+ html4_entities.decode(html4_entities.encode(string, :hexadecimal))
84
+ )
85
+ end
86
+ end
87
+
88
+ def each_mapping(flavor)
89
+ HTMLEntities::MAPPINGS[flavor].each do |name, codepoint|
90
+ yield name, [codepoint].pack('U')
91
+ end
92
+ end
93
+
94
+ end
@@ -1,4 +1,4 @@
1
- $: << File.dirname(__FILE__) + '/../lib/'
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
  require 'htmlentities/string'
3
3
  require 'test/unit'
4
4
 
File without changes
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'htmlentities'
3
+ require 'test/unit'
4
+
5
+ $KCODE = 'u'
6
+
7
+ class HTMLEntities::XHTML1Test < Test::Unit::TestCase
8
+
9
+ attr_reader :html_entities
10
+
11
+ def setup
12
+ @html_entities = HTMLEntities.new('xhtml1')
13
+ end
14
+
15
+ def test_should_encode_apos_entity
16
+ assert_equal "&apos;", html_entities.encode("'", :basic)
17
+ end
18
+
19
+ def test_should_decode_apos_entity
20
+ assert_equal "é'", html_entities.decode("&eacute;&apos;")
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: htmlentities
5
5
  version: !ruby/object:Gem::Version
6
- version: 3.0.1
7
- date: 2006-04-09 00:00:00 +01:00
8
- summary: A module for encoding and decoding of HTML/XML entities from/to their corresponding UTF-8 codepoints. Optional String class extension for same.
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
9
  require_paths:
10
10
  - lib
11
11
  email: pbattley@gmail.com
12
- homepage:
12
+ homepage: http://htmlentities.rubyforge.org/
13
13
  rubyforge_project:
14
14
  description:
15
15
  autorequire:
@@ -25,25 +25,33 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Paul Battley
30
31
  files:
31
32
  - lib/htmlentities.rb
33
+ - lib/htmlentities/html4.rb
34
+ - lib/htmlentities/legacy.rb
32
35
  - lib/htmlentities/string.rb
33
- - test/all.rb
36
+ - lib/htmlentities/xhtml1.rb
34
37
  - test/entities_test.rb
38
+ - test/html4_test.rb
39
+ - test/legacy_test.rb
40
+ - test/roundtrip_test.rb
35
41
  - test/string_test.rb
36
- - README
37
- - CHANGES
38
- - COPYING
42
+ - test/test_all.rb
43
+ - test/xhtml1_test.rb
44
+ - README.txt
45
+ - History.txt
46
+ - COPYING.txt
39
47
  test_files:
40
- - test/all.rb
48
+ - test/test_all.rb
41
49
  rdoc_options: []
42
50
 
43
51
  extra_rdoc_files:
44
- - README
45
- - CHANGES
46
- - COPYING
52
+ - README.txt
53
+ - History.txt
54
+ - COPYING.txt
47
55
  executables: []
48
56
 
49
57
  extensions: []
data/README DELETED
@@ -1,23 +0,0 @@
1
- == HTMLEntities
2
-
3
- HTML entity encoding and decoding for Ruby
4
-
5
- The HTMLEntities module facilitates encoding and decoding of
6
- HTML/XML entities from/to their corresponding UTF-8 codepoints.
7
-
8
- To install (requires root/admin privileges):
9
-
10
- ruby setup.rb
11
-
12
- Alternatively, you can just use the gem.
13
-
14
- == Licence
15
-
16
- This code is free to use under the terms of the MIT licence. If you'd like to
17
- negotiate a different licence for a specific use, just contact me -- I'll
18
- almost certainly permit it.
19
-
20
- == Contact
21
-
22
- Comments are welcome. Send an email to pbattley@gmail.com.
23
-