summaryrefslogtreecommitdiff
path: root/ext/cgi/escape
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-20 08:33:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-20 08:33:33 +0000
commit20cd25c86fd28eb1b5068d0db607e6aa33107f65 (patch)
treecd5ddf4f9592ba06dc6fe2ad7144459d09de3241 /ext/cgi/escape
parent86b1179a03791002b6428f5b49754d7411933e9e (diff)
cgi/util.rb: remove CGI::Util#_unescape
* ext/cgi/escape/escape.c (cgiesc_unescape): define unescape method instead of _unescape, and should pass the optional argument to the super method. * lib/cgi/util.rb (CGI::Util#_unescape): remove intermediate method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/cgi/escape')
-rw-r--r--ext/cgi/escape/escape.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c
index 4f6a82a..75278a5 100644
--- a/ext/cgi/escape/escape.c
+++ b/ext/cgi/escape/escape.c
@@ -369,17 +369,34 @@ cgiesc_escape(VALUE self, VALUE str)
}
}
-/* :nodoc: */
static VALUE
-cgiesc_unescape(VALUE self, VALUE str, VALUE enc)
+accept_charset(int argc, VALUE *argv, VALUE self)
{
+ if (argc > 0)
+ return argv[0];
+ return rb_cvar_get(CLASS_OF(self), rb_intern("@@accept_charset"));
+}
+
+/*
+ * call-seq:
+ * CGI.unescape(string, encoding=@@accept_charset) -> string
+ *
+ * Returns URL-unescaped string.
+ *
+ */
+static VALUE
+cgiesc_unescape(int argc, VALUE *argv, VALUE self)
+{
+ VALUE str = (rb_check_arity(argc, 1, 2), argv[0]);
+
StringValue(str);
if (rb_enc_str_asciicompat_p(str)) {
+ VALUE enc = accept_charset(argc-1, argv+1, self);
return optimized_unescape(str, enc);
}
else {
- return rb_call_super(1, &str);
+ return rb_call_super(argc, argv);
}
}
@@ -392,7 +409,7 @@ Init_escape(void)
rb_define_method(rb_mEscape, "escapeHTML", cgiesc_escape_html, 1);
rb_define_method(rb_mEscape, "unescapeHTML", cgiesc_unescape_html, 1);
rb_define_method(rb_mEscape, "escape", cgiesc_escape, 1);
- rb_define_private_method(rb_mEscape, "_unescape", cgiesc_unescape, 2);
+ rb_define_method(rb_mEscape, "unescape", cgiesc_unescape, -1);
rb_prepend_module(rb_mUtil, rb_mEscape);
rb_extend_object(rb_cCGI, rb_mEscape);
}