diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2013-10-22 00:49:55 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2013-10-22 00:49:55 -0600 |
| commit | 6d8ed54890f4ebebc655b278bc2de347bbeaf6e0 (patch) | |
| tree | f1ddffaddf175d5c72239b088d4a71575fa4fed9 | |
| parent | 2f05fe6d56c7ed143e4c243ecf0c2a139b01593b (diff) | |
update Helpers#encode_uri for Opal, add tests
| -rw-r--r-- | lib/asciidoctor/helpers.rb | 7 | ||||
| -rw-r--r-- | test/substitutions_test.rb | 15 |
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb index eab10490..01319073 100644 --- a/lib/asciidoctor/helpers.rb +++ b/lib/asciidoctor/helpers.rb @@ -34,12 +34,7 @@ module Helpers # returns an encoded version of the str def self.encode_uri(str) str.gsub(REGEXP[:uri_encode_chars]) do - match = $& - buf = '' - match.each_byte do |c| - buf << sprintf('%%%02X', c) - end - buf + $&.each_byte.map {|c| sprintf '%%%02X', c}.join end end diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb index 79137a52..080ac855 100644 --- a/test/substitutions_test.rb +++ b/test/substitutions_test.rb @@ -1164,4 +1164,19 @@ foo — ) assert_equal [:specialcharacters], block.subs end end + + # TODO move to helpers_test.rb + context 'Helpers' do + test 'should URI encode non-word characters generally' do + given = ' /%&?\\' + expect = '%20%2F%25%26%3F%5C' + assert_equal expect, (Asciidoctor::Helpers.encode_uri given) + end + + test 'should not URI select non-word characters' do + given = '-.!~*\';:@=+$,()[]' + expect = given + assert_equal expect, (Asciidoctor::Helpers.encode_uri given) + end + end end |
