Skip to content

Commit 9d1161e

Browse files
byroothsbt
authored andcommitted
Add snake case aliases for escapeURIComponent
As agreed in [Feature #18822]
1 parent 6ddd5fc commit 9d1161e

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

ext/cgi/escape/escape.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ InitVM_escape(void)
458458
rb_define_method(rb_mEscape, "escapeHTML", cgiesc_escape_html, 1);
459459
rb_define_method(rb_mEscape, "unescapeHTML", cgiesc_unescape_html, 1);
460460
rb_define_method(rb_mEscape, "escapeURIComponent", cgiesc_escape_uri_component, 1);
461+
rb_define_alias(rb_mEscape, "escape_uri_component", "escapeURIComponent");
461462
rb_define_method(rb_mEscape, "unescapeURIComponent", cgiesc_unescape_uri_component, -1);
463+
rb_define_alias(rb_mEscape, "unescape_uri_component", "unescapeURIComponent");
462464
rb_define_method(rb_mEscape, "escape", cgiesc_escape, 1);
463465
rb_define_method(rb_mEscape, "unescape", cgiesc_unescape, -1);
464466
rb_prepend_module(rb_mUtil, rb_mEscape);

lib/cgi/util.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def escapeURIComponent(string)
4646
end
4747
buffer.force_encoding(encoding)
4848
end
49+
alias escape_uri_component escapeURIComponent
4950

5051
# URL-decode a string following RFC 3986 with encoding(optional).
5152
# string = CGI.unescapeURIComponent("%27Stop%21%27+said%20Fred")
@@ -59,6 +60,8 @@ def unescapeURIComponent(string, encoding = @@accept_charset)
5960
str.valid_encoding? ? str : str.force_encoding(string.encoding)
6061
end
6162

63+
alias unescape_uri_component unescapeURIComponent
64+
6265
# The set of special characters and their escaped values
6366
TABLE_FOR_ESCAPE_HTML__ = {
6467
"'" => ''',

test/cgi/test_cgi_util.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def test_cgi_escapeURIComponent
7474
assert_equal('%26%3C%3E%22%20%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI.escapeURIComponent(@str1).ascii_only?) if defined?(::Encoding)
7575
end
7676

77+
def test_cgi_escape_uri_component
78+
assert_equal('%26%3C%3E%22%20%E3%82%86%E3%82%93%E3%82%86%E3%82%93', CGI.escape_uri_component(@str1))
79+
end
80+
7781
def test_cgi_escapeURIComponent_with_unreserved_characters
7882
assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
7983
CGI.escapeURIComponent("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
@@ -101,6 +105,11 @@ def test_cgi_unescapeURIComponent
101105
assert_equal("\u{30E1 30E2 30EA 691C 7D22}", CGI.unescapeURIComponent("\u{30E1 30E2 30EA}%E6%A4%9C%E7%B4%A2"))
102106
end
103107

108+
def test_cgi_unescape_uri_component
109+
str = CGI.unescape_uri_component('%26%3C%3E%22%20%E3%82%86%E3%82%93%E3%82%86%E3%82%93')
110+
assert_equal(@str1, str)
111+
end
112+
104113
def test_cgi_unescapeURIComponent_preserve_encoding
105114
assert_equal(Encoding::US_ASCII, CGI.unescapeURIComponent("%C0%3C%3C".dup.force_encoding("US-ASCII")).encoding)
106115
assert_equal(Encoding::ASCII_8BIT, CGI.unescapeURIComponent("%C0%3C%3C".dup.force_encoding("ASCII-8BIT")).encoding)

0 commit comments

Comments
 (0)