mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from
ECONV_HTML_TEXT_ENCODER. (ECONV_XML_ATTR_ENCODER): renamed from ECONV_HTML_ATTR_ENCODER. * enc/trans/escape.trans: follow the renaming. * transcode.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d98bc00582
commit
76b3063022
5 changed files with 75 additions and 65 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Sat Sep 6 23:03:41 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from
|
||||
ECONV_HTML_TEXT_ENCODER.
|
||||
(ECONV_XML_ATTR_ENCODER): renamed from ECONV_HTML_ATTR_ENCODER.
|
||||
|
||||
* enc/trans/escape.trans: follow the renaming.
|
||||
|
||||
* transcode.c: ditto.
|
||||
|
||||
Sat Sep 6 21:35:52 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/socket/mkconstants.rb: add some IPV6 constans. [ruby-dev:36175]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "transcode_data.h"
|
||||
|
||||
static int
|
||||
fun_so_escape_html_chref(void *statep, const unsigned char *s, size_t l, unsigned char *o)
|
||||
fun_so_escape_xml_chref(void *statep, const unsigned char *s, size_t l, unsigned char *o)
|
||||
{
|
||||
switch (*s) {
|
||||
case '&':
|
||||
|
@ -45,16 +45,16 @@ fun_so_escape_html_chref(void *statep, const unsigned char *s, size_t l, unsigne
|
|||
map_amp["26"] = :func_so
|
||||
transcode_generate_node(ActionMap.parse(map_amp), "escape_amp_as_chref")
|
||||
|
||||
map_html_text = {}
|
||||
map_html_text["{00-25,27-3B,3D,3F-FF}"] = :nomap
|
||||
map_html_text["26"] = :func_so
|
||||
map_html_text["3C"] = :func_so
|
||||
map_html_text["3E"] = :func_so
|
||||
transcode_generate_node(ActionMap.parse(map_html_text), "escape_html_text")
|
||||
map_xml_text = {}
|
||||
map_xml_text["{00-25,27-3B,3D,3F-FF}"] = :nomap
|
||||
map_xml_text["26"] = :func_so
|
||||
map_xml_text["3C"] = :func_so
|
||||
map_xml_text["3E"] = :func_so
|
||||
transcode_generate_node(ActionMap.parse(map_xml_text), "escape_xml_text")
|
||||
|
||||
map_html_attr = {}
|
||||
map_html_attr["{00-FF}"] = :func_so
|
||||
transcode_generate_node(ActionMap.parse(map_html_attr), "escape_html_attr")
|
||||
map_xml_attr = {}
|
||||
map_xml_attr["{00-FF}"] = :func_so
|
||||
transcode_generate_node(ActionMap.parse(map_xml_attr), "escape_xml_attr")
|
||||
%>
|
||||
|
||||
<%= transcode_generated_code %>
|
||||
|
@ -68,26 +68,26 @@ rb_escape_amp_as_chref = {
|
|||
5, /* max_output */
|
||||
stateless_converter, /* stateful_type */
|
||||
0, NULL, NULL,
|
||||
NULL, NULL, NULL, &fun_so_escape_html_chref
|
||||
NULL, NULL, NULL, &fun_so_escape_xml_chref
|
||||
};
|
||||
|
||||
static const rb_transcoder
|
||||
rb_escape_html_text = {
|
||||
"", "html-text-escaped", escape_html_text,
|
||||
rb_escape_xml_text = {
|
||||
"", "xml-text-escaped", escape_xml_text,
|
||||
TRANSCODE_TABLE_INFO,
|
||||
1, /* input_unit_length */
|
||||
1, /* max_input */
|
||||
5, /* max_output */
|
||||
stateless_converter, /* stateful_type */
|
||||
0, NULL, NULL,
|
||||
NULL, NULL, NULL, &fun_so_escape_html_chref
|
||||
NULL, NULL, NULL, &fun_so_escape_xml_chref
|
||||
};
|
||||
|
||||
#define END 0
|
||||
#define NORMAL 1
|
||||
|
||||
static int
|
||||
escape_html_attr_init(void *statep)
|
||||
escape_xml_attr_init(void *statep)
|
||||
{
|
||||
unsigned char *sp = statep;
|
||||
*sp = END;
|
||||
|
@ -95,7 +95,7 @@ escape_html_attr_init(void *statep)
|
|||
}
|
||||
|
||||
static int
|
||||
fun_so_escape_html_attr(void *statep, const unsigned char *s, size_t l, unsigned char *o)
|
||||
fun_so_escape_xml_attr(void *statep, const unsigned char *s, size_t l, unsigned char *o)
|
||||
{
|
||||
unsigned char *sp = statep;
|
||||
int n = 0;
|
||||
|
@ -108,7 +108,7 @@ fun_so_escape_html_attr(void *statep, const unsigned char *s, size_t l, unsigned
|
|||
case '<':
|
||||
case '>':
|
||||
case '"':
|
||||
n += fun_so_escape_html_chref(statep, s, l, o+n);
|
||||
n += fun_so_escape_xml_chref(statep, s, l, o+n);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -119,7 +119,7 @@ fun_so_escape_html_attr(void *statep, const unsigned char *s, size_t l, unsigned
|
|||
}
|
||||
|
||||
static int
|
||||
escape_html_attr_finish(void *statep, unsigned char *o)
|
||||
escape_xml_attr_finish(void *statep, unsigned char *o)
|
||||
{
|
||||
unsigned char *sp = statep;
|
||||
int n = 0;
|
||||
|
@ -135,23 +135,23 @@ escape_html_attr_finish(void *statep, unsigned char *o)
|
|||
}
|
||||
|
||||
static const rb_transcoder
|
||||
rb_escape_html_attr = {
|
||||
"", "html-attr-escaped", escape_html_attr,
|
||||
rb_escape_xml_attr = {
|
||||
"", "xml-attr-escaped", escape_xml_attr,
|
||||
TRANSCODE_TABLE_INFO,
|
||||
1, /* input_unit_length */
|
||||
1, /* max_input */
|
||||
7, /* max_output */
|
||||
stateful_encoder, /* stateful_type */
|
||||
1, escape_html_attr_init, escape_html_attr_init,
|
||||
NULL, NULL, NULL, fun_so_escape_html_attr,
|
||||
escape_html_attr_finish
|
||||
1, escape_xml_attr_init, escape_xml_attr_init,
|
||||
NULL, NULL, NULL, fun_so_escape_xml_attr,
|
||||
escape_xml_attr_finish
|
||||
};
|
||||
|
||||
void
|
||||
Init_escape(void)
|
||||
{
|
||||
rb_register_transcoder(&rb_escape_amp_as_chref);
|
||||
rb_register_transcoder(&rb_escape_html_text);
|
||||
rb_register_transcoder(&rb_escape_html_attr);
|
||||
rb_register_transcoder(&rb_escape_xml_text);
|
||||
rb_register_transcoder(&rb_escape_xml_attr);
|
||||
}
|
||||
|
||||
|
|
|
@ -263,8 +263,8 @@ void rb_econv_binmode(rb_econv_t *ec);
|
|||
/* usable only if source encoding is ascii compatible */
|
||||
#define ECONV_CRLF_NEWLINE_ENCODER 0x0200
|
||||
#define ECONV_CR_NEWLINE_ENCODER 0x0400
|
||||
#define ECONV_HTML_TEXT_ENCODER 0x0800
|
||||
#define ECONV_HTML_ATTR_ENCODER 0x1000
|
||||
#define ECONV_XML_TEXT_ENCODER 0x0800
|
||||
#define ECONV_XML_ATTR_ENCODER 0x1000
|
||||
|
||||
/* end of flags for rb_econv_open */
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
assert_nil(Encoding::Converter.stateless_encoding("UTF-8"))
|
||||
assert_nil(Encoding::Converter.stateless_encoding("UTF-16BE"))
|
||||
assert_nil(Encoding::Converter.stateless_encoding(Encoding::UTF_8))
|
||||
assert_nil(Encoding::Converter.stateless_encoding("html-attr-escaped"))
|
||||
assert_nil(Encoding::Converter.stateless_encoding("xml-attr-escaped"))
|
||||
end
|
||||
|
||||
def test_stateless_encoding_iso2022jp
|
||||
|
@ -728,54 +728,54 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
assert_equal("&", ec.convert("&"))
|
||||
end
|
||||
|
||||
def test_html_escape_text
|
||||
def test_xml_escape_text
|
||||
ec = Encoding::Converter.new("", "amp-escaped")
|
||||
assert_equal('&<>"', ec.convert("&<>\""))
|
||||
assert_equal('', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("", "html-text-escaped")
|
||||
ec = Encoding::Converter.new("", "xml-text-escaped")
|
||||
assert_equal('&<>"', ec.convert("&<>\""))
|
||||
assert_equal('', ec.finish)
|
||||
end
|
||||
|
||||
def test_html_escape_attr
|
||||
ec = Encoding::Converter.new("", "html-attr-escaped")
|
||||
def test_xml_escape_attr
|
||||
ec = Encoding::Converter.new("", "xml-attr-escaped")
|
||||
assert_equal('""', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("", "html-attr-escaped")
|
||||
ec = Encoding::Converter.new("", "xml-attr-escaped")
|
||||
assert_equal('', ec.convert(""))
|
||||
assert_equal('""', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("", "html-attr-escaped")
|
||||
ec = Encoding::Converter.new("", "xml-attr-escaped")
|
||||
assert_equal('""', ec.convert('"'))
|
||||
assert_equal('"', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("", "html-attr-escaped")
|
||||
ec = Encoding::Converter.new("", "xml-attr-escaped")
|
||||
assert_equal('"&<>"', ec.convert("&<>\""))
|
||||
assert_equal('"', ec.finish)
|
||||
end
|
||||
|
||||
def test_html_escape_with_charref
|
||||
ec = Encoding::Converter.new("utf-8", "euc-jp", Encoding::Converter::HTML_TEXT_ENCODER|Encoding::Converter::UNDEF_HEX_CHARREF)
|
||||
def test_xml_escape_with_charref
|
||||
ec = Encoding::Converter.new("utf-8", "euc-jp", Encoding::Converter::XML_TEXT_ENCODER|Encoding::Converter::UNDEF_HEX_CHARREF)
|
||||
assert_equal('<♥>&"♡"', ec.convert("<\u2665>&\"\u2661\""))
|
||||
assert_equal('', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("utf-8", "euc-jp", Encoding::Converter::HTML_ATTR_ENCODER|Encoding::Converter::UNDEF_HEX_CHARREF)
|
||||
ec = Encoding::Converter.new("utf-8", "euc-jp", Encoding::Converter::XML_ATTR_ENCODER|Encoding::Converter::UNDEF_HEX_CHARREF)
|
||||
assert_equal('"<♥>&"♡"', ec.convert("<\u2665>&\"\u2661\""))
|
||||
assert_equal('"', ec.finish)
|
||||
|
||||
ec = Encoding::Converter.new("utf-8", "iso-2022-jp", Encoding::Converter::HTML_TEXT_ENCODER)
|
||||
ec = Encoding::Converter.new("utf-8", "iso-2022-jp", Encoding::Converter::XML_TEXT_ENCODER)
|
||||
assert_equal("&\e$B$&\e(B&".force_encoding("iso-2022-jp"), ec.convert("&\u3046&"))
|
||||
assert_equal('', ec.finish)
|
||||
end
|
||||
|
||||
def test_html_hasharg
|
||||
def test_xml_hasharg
|
||||
assert_equal("&\e$B$&\e(B♥&\"'".force_encoding("iso-2022-jp"),
|
||||
"&\u3046\u2665&\"'".encode("iso-2022-jp", html: :text))
|
||||
"&\u3046\u2665&\"'".encode("iso-2022-jp", xml: :text))
|
||||
assert_equal("\"&\e$B$&\e(B♡&"'\"".force_encoding("iso-2022-jp"),
|
||||
"&\u3046\u2661&\"'".encode("iso-2022-jp", html: :attr))
|
||||
"&\u3046\u2661&\"'".encode("iso-2022-jp", xml: :attr))
|
||||
|
||||
assert_equal("&\u3046\u2661&\"'".force_encoding("utf-8"),
|
||||
"&\u3046\u2661&\"'".encode("utf-8", html: :text))
|
||||
"&\u3046\u2661&\"'".encode("utf-8", xml: :text))
|
||||
end
|
||||
end
|
||||
|
|
44
transcode.c
44
transcode.c
|
@ -21,7 +21,7 @@ VALUE rb_eNoConverter;
|
|||
VALUE rb_cEncodingConverter;
|
||||
|
||||
static VALUE sym_invalid, sym_undef, sym_ignore, sym_replace;
|
||||
static VALUE sym_html, sym_text, sym_attr;
|
||||
static VALUE sym_xml, sym_text, sym_attr;
|
||||
static VALUE sym_universal_newline_decoder;
|
||||
static VALUE sym_crlf_newline_encoder;
|
||||
static VALUE sym_cr_newline_encoder;
|
||||
|
@ -895,8 +895,8 @@ rb_econv_open(const char *sname, const char *dname, int ecflags)
|
|||
(ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER))
|
||||
return NULL;
|
||||
|
||||
if ((ecflags & ECONV_HTML_TEXT_ENCODER) &&
|
||||
(ecflags & ECONV_HTML_ATTR_ENCODER))
|
||||
if ((ecflags & ECONV_XML_TEXT_ENCODER) &&
|
||||
(ecflags & ECONV_XML_ATTR_ENCODER))
|
||||
return NULL;
|
||||
|
||||
num_encoders = 0;
|
||||
|
@ -906,11 +906,11 @@ rb_econv_open(const char *sname, const char *dname, int ecflags)
|
|||
if (ecflags & ECONV_CR_NEWLINE_ENCODER)
|
||||
if (!(encoders[num_encoders++] = get_transcoder_entry("", "cr_newline")))
|
||||
return NULL;
|
||||
if (ecflags & ECONV_HTML_TEXT_ENCODER)
|
||||
if (!(encoders[num_encoders++] = get_transcoder_entry("", "html-text-escaped")))
|
||||
if (ecflags & ECONV_XML_TEXT_ENCODER)
|
||||
if (!(encoders[num_encoders++] = get_transcoder_entry("", "xml-text-escaped")))
|
||||
return NULL;
|
||||
if (ecflags & ECONV_HTML_ATTR_ENCODER)
|
||||
if (!(encoders[num_encoders++] = get_transcoder_entry("", "html-attr-escaped")))
|
||||
if (ecflags & ECONV_XML_ATTR_ENCODER)
|
||||
if (!(encoders[num_encoders++] = get_transcoder_entry("", "xml-attr-escaped")))
|
||||
return NULL;
|
||||
|
||||
num_decoders = 0;
|
||||
|
@ -1791,8 +1791,8 @@ econv_description(const char *sname, const char *dname, int ecflags, VALUE mesg)
|
|||
if (ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
|
||||
ECONV_CRLF_NEWLINE_ENCODER|
|
||||
ECONV_CR_NEWLINE_ENCODER|
|
||||
ECONV_HTML_TEXT_ENCODER|
|
||||
ECONV_HTML_ATTR_ENCODER)) {
|
||||
ECONV_XML_TEXT_ENCODER|
|
||||
ECONV_XML_ATTR_ENCODER)) {
|
||||
const char *pre = "";
|
||||
if (has_description)
|
||||
rb_str_cat2(mesg, " with ");
|
||||
|
@ -1808,13 +1808,13 @@ econv_description(const char *sname, const char *dname, int ecflags, VALUE mesg)
|
|||
rb_str_cat2(mesg, pre); pre = ",";
|
||||
rb_str_cat2(mesg, "CR-newline");
|
||||
}
|
||||
if (ecflags & ECONV_HTML_TEXT_ENCODER) {
|
||||
if (ecflags & ECONV_XML_TEXT_ENCODER) {
|
||||
rb_str_cat2(mesg, pre); pre = ",";
|
||||
rb_str_cat2(mesg, "HTML-text");
|
||||
rb_str_cat2(mesg, "XML-text");
|
||||
}
|
||||
if (ecflags & ECONV_HTML_ATTR_ENCODER) {
|
||||
if (ecflags & ECONV_XML_ATTR_ENCODER) {
|
||||
rb_str_cat2(mesg, pre); pre = ",";
|
||||
rb_str_cat2(mesg, "HTML-attr");
|
||||
rb_str_cat2(mesg, "XML-attr");
|
||||
}
|
||||
has_description = 1;
|
||||
}
|
||||
|
@ -2166,17 +2166,17 @@ econv_opts(VALUE opt)
|
|||
rb_raise(rb_eArgError, "unknown value for undefined character option");
|
||||
}
|
||||
|
||||
v = rb_hash_aref(opt, sym_html);
|
||||
v = rb_hash_aref(opt, sym_xml);
|
||||
if (!NIL_P(v)) {
|
||||
v = rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym");
|
||||
if (v==sym_text) {
|
||||
ecflags |= ECONV_HTML_TEXT_ENCODER|ECONV_UNDEF_HEX_CHARREF;
|
||||
ecflags |= ECONV_XML_TEXT_ENCODER|ECONV_UNDEF_HEX_CHARREF;
|
||||
}
|
||||
else if (v==sym_attr) {
|
||||
ecflags |= ECONV_HTML_ATTR_ENCODER|ECONV_UNDEF_HEX_CHARREF;
|
||||
ecflags |= ECONV_XML_ATTR_ENCODER|ECONV_UNDEF_HEX_CHARREF;
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eArgError, "unexpected value for html option: %s", rb_id2name(SYM2ID(v)));
|
||||
rb_raise(rb_eArgError, "unexpected value for xml option: %s", rb_id2name(SYM2ID(v)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2328,8 +2328,8 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts)
|
|||
if ((ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
|
||||
ECONV_CRLF_NEWLINE_ENCODER|
|
||||
ECONV_CR_NEWLINE_ENCODER|
|
||||
ECONV_HTML_TEXT_ENCODER|
|
||||
ECONV_HTML_ATTR_ENCODER)) == 0) {
|
||||
ECONV_XML_TEXT_ENCODER|
|
||||
ECONV_XML_ATTR_ENCODER)) == 0) {
|
||||
if (senc && senc == denc) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -3526,7 +3526,7 @@ Init_transcode(void)
|
|||
sym_undef = ID2SYM(rb_intern("undef"));
|
||||
sym_ignore = ID2SYM(rb_intern("ignore"));
|
||||
sym_replace = ID2SYM(rb_intern("replace"));
|
||||
sym_html = ID2SYM(rb_intern("html"));
|
||||
sym_xml = ID2SYM(rb_intern("xml"));
|
||||
sym_text = ID2SYM(rb_intern("text"));
|
||||
sym_attr = ID2SYM(rb_intern("attr"));
|
||||
|
||||
|
@ -3572,8 +3572,8 @@ Init_transcode(void)
|
|||
rb_define_const(rb_cEncodingConverter, "UNIVERSAL_NEWLINE_DECODER", INT2FIX(ECONV_UNIVERSAL_NEWLINE_DECODER));
|
||||
rb_define_const(rb_cEncodingConverter, "CRLF_NEWLINE_ENCODER", INT2FIX(ECONV_CRLF_NEWLINE_ENCODER));
|
||||
rb_define_const(rb_cEncodingConverter, "CR_NEWLINE_ENCODER", INT2FIX(ECONV_CR_NEWLINE_ENCODER));
|
||||
rb_define_const(rb_cEncodingConverter, "HTML_TEXT_ENCODER", INT2FIX(ECONV_HTML_TEXT_ENCODER));
|
||||
rb_define_const(rb_cEncodingConverter, "HTML_ATTR_ENCODER", INT2FIX(ECONV_HTML_ATTR_ENCODER));
|
||||
rb_define_const(rb_cEncodingConverter, "XML_TEXT_ENCODER", INT2FIX(ECONV_XML_TEXT_ENCODER));
|
||||
rb_define_const(rb_cEncodingConverter, "XML_ATTR_ENCODER", INT2FIX(ECONV_XML_ATTR_ENCODER));
|
||||
|
||||
rb_define_method(rb_eConversionUndefined, "source_encoding_name", ecerr_source_encoding_name, 0);
|
||||
rb_define_method(rb_eConversionUndefined, "destination_encoding_name", ecerr_destination_encoding_name, 0);
|
||||
|
|
Loading…
Reference in a new issue