htmlentities 4.2.3 → 4.2.4

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.
@@ -3,19 +3,25 @@ class HTMLEntities
3
3
  def initialize(flavor)
4
4
  @flavor = flavor
5
5
  @map = HTMLEntities::MAPPINGS[@flavor]
6
- @named_entity_regexp = named_entity_regexp
6
+ @entity_regexp = entity_regexp
7
7
  end
8
8
 
9
9
  def decode(source)
10
- source.to_s.gsub(@named_entity_regexp) {
11
- (codepoint = @map[$1]) ? [codepoint].pack('U') : $&
12
- }.gsub(/&#(?:([0-9]{1,7})|x([0-9a-f]{1,6}));/i) {
13
- $1 ? [$1.to_i].pack('U') : [$2.to_i(16)].pack('U')
10
+ source.to_s.gsub(@entity_regexp) {
11
+ if $1 && codepoint = @map[$1]
12
+ [codepoint].pack('U')
13
+ elsif $2
14
+ [$2.to_i(10)].pack('U')
15
+ elsif $3
16
+ [$3.to_i(16)].pack('U')
17
+ else
18
+ $&
19
+ end
14
20
  }
15
21
  end
16
22
 
17
23
  private
18
- def named_entity_regexp
24
+ def entity_regexp
19
25
  key_lengths = @map.keys.map{ |k| k.length }
20
26
  entity_name_pattern =
21
27
  if @flavor == 'expanded'
@@ -23,7 +29,7 @@ class HTMLEntities
23
29
  else
24
30
  '[a-z][a-z0-9]'
25
31
  end
26
- /&(#{ entity_name_pattern }{#{ key_lengths.min - 1 },#{ key_lengths.max - 1 }});/i
32
+ /&(?:(#{entity_name_pattern}{#{key_lengths.min - 1},#{key_lengths.max - 1}})|#([0-9]{1,7})|#x([0-9a-f]{1,6}));/i
27
33
  end
28
34
  end
29
35
  end
@@ -2,7 +2,7 @@ class HTMLEntities
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 4
4
4
  MINOR = 2
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -194,6 +194,13 @@ class HTMLEntities::EntitiesTest < Test::Unit::TestCase
194
194
  end
195
195
  end
196
196
 
197
+ # Reported by ckruse
198
+ def test_should_decode_only_first_element_in_masked_entities
199
+ input = '&amp;#3346;'
200
+ expected = '&#3346;'
201
+ assert_decode expected, input
202
+ end
203
+
197
204
  def test_should_ducktype_parameter_to_string_before_encoding
198
205
  pseudo_string = PseudoString.new('foo')
199
206
  assert_decode('foo', pseudo_string)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmlentities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 4
8
8
  - 2
9
- - 3
10
- version: 4.2.3
9
+ - 4
10
+ version: 4.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Battley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-07 00:00:00 +00:00
18
+ date: 2011-01-30 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,25 +30,25 @@ extra_rdoc_files:
30
30
  - History.txt
31
31
  - COPYING.txt
32
32
  files:
33
- - lib/htmlentities.rb
34
- - lib/htmlentities/legacy.rb
35
- - lib/htmlentities/flavors.rb
36
33
  - lib/htmlentities/version.rb
34
+ - lib/htmlentities/flavors.rb
37
35
  - lib/htmlentities/encoder.rb
36
+ - lib/htmlentities/legacy.rb
37
+ - lib/htmlentities/mappings/html4.rb
38
38
  - lib/htmlentities/mappings/expanded.rb
39
39
  - lib/htmlentities/mappings/xhtml1.rb
40
- - lib/htmlentities/mappings/html4.rb
41
40
  - lib/htmlentities/decoder.rb
41
+ - lib/htmlentities.rb
42
+ - test/entities_test.rb
42
43
  - test/xhtml1_test.rb
43
- - test/html4_test.rb
44
- - test/test_all.rb
44
+ - test/roundtrip_test.rb
45
45
  - test/legacy_test.rb
46
46
  - test/expanded_test.rb
47
- - test/roundtrip_test.rb
48
- - test/entities_test.rb
49
- - perf/performance.rb
47
+ - test/test_all.rb
48
+ - test/html4_test.rb
50
49
  - perf/profile.rb
51
50
  - perf/benchmark.rb
51
+ - perf/performance.rb
52
52
  - README.rdoc
53
53
  - History.txt
54
54
  - COPYING.txt