summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-05-16 14:46:46 -0400
committerGitHub <noreply@github.com>2024-05-16 12:46:46 -0600
commitf1da34a14442e49747a81a40a40815856c9f894e (patch)
treee23a90bdd5623d5c571380ad40468d837685027d
parentd3ded5a0d5b39556d5a0d04a8c9af0acecb8f759 (diff)
resolves #4576 encode spaces in mailto links as %20, in accordance with RFC 3986, instead of using + (PR #4591)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/helpers.rb7
-rw-r--r--test/helpers_test.rb2
-rw-r--r--test/substitutions_test.rb6
4 files changed, 10 insertions, 6 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 6fe7130d..d08f75ff 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -43,6 +43,7 @@ Compliance::
* Disallow the use of dot (`.`) in the name of a named element attribute (#4147)
* Disallow the use of the left square bracket in an attribute list on formatted text (#4306)
* Update stylesheet to use break-after in place of page-break-before/after/inside (#3466)
+ * Encode spaces in mailto links as %20, in accordance with RFC 3986, instead of using + (#4576)
* Drop support for Ruby < 2.7 and JRuby < 9.2
* Update latest JRuby in CI workflow to 9.4.2.0
diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb
index fc5a37f0..e92aa978 100644
--- a/lib/asciidoctor/helpers.rb
+++ b/lib/asciidoctor/helpers.rb
@@ -146,10 +146,13 @@ module Helpers
})
)
end
+ elsif (CGI = ::CGI).respond_to? :escapeURIComponent
+ def encode_uri_component str
+ CGI.escapeURIComponent str
+ end
else
- CGI = ::CGI
def encode_uri_component str
- CGI.escape str
+ (CGI.escape str).gsub '+', '%20'
end
end
diff --git a/test/helpers_test.rb b/test/helpers_test.rb
index 38b0eeba..cfc2fe00 100644
--- a/test/helpers_test.rb
+++ b/test/helpers_test.rb
@@ -6,7 +6,7 @@ context 'Helpers' do
context 'URI Encoding' do
test 'should URI encode non-word characters generally' do
given = ' !*/%&?\\='
- expect = '+%21%2A%2F%25%26%3F%5C%3D'
+ expect = '%20%21%2A%2F%25%26%3F%5C%3D'
assert_equal expect, (Asciidoctor::Helpers.encode_uri_component given)
end
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index a4c6c37d..4cd74ebd 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -677,17 +677,17 @@ context 'Substitutions' do
test 'a mailto macro with text and subject should be interpreted as a mailto link' do
para = block_from_string 'mailto:doc.writer@asciidoc.org[Doc Writer, Pull request]'
- assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull+request">Doc Writer</a>', para.sub_macros(para.source)
+ assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull%20request">Doc Writer</a>', para.sub_macros(para.source)
end
test 'a mailto macro with text, subject and body should be interpreted as a mailto link' do
para = block_from_string 'mailto:doc.writer@asciidoc.org[Doc Writer, Pull request, Please accept my pull request]'
- assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull+request&amp;body=Please+accept+my+pull+request">Doc Writer</a>', para.sub_macros(para.source)
+ assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull%20request&amp;body=Please%20accept%20my%20pull%20request">Doc Writer</a>', para.sub_macros(para.source)
end
test 'a mailto macro with subject and body only should use e-mail as text' do
para = block_from_string 'mailto:doc.writer@asciidoc.org[,Pull request,Please accept my pull request]'
- assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull+request&amp;body=Please+accept+my+pull+request">doc.writer@asciidoc.org</a>', para.sub_macros(para.source)
+ assert_equal '<a href="mailto:doc.writer@asciidoc.org?subject=Pull%20request&amp;body=Please%20accept%20my%20pull%20request">doc.writer@asciidoc.org</a>', para.sub_macros(para.source)
end
test 'a mailto macro supports id and role attributes' do