diff --git a/ChangeLog b/ChangeLog index ba8d508994..e4d5a53a18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sun Sep 7 00:37:25 2008 Tanaka Akira + + * include/ruby/encoding.h (ECONV_ERROR_HANDLER_MASK): defined. + (ECONV_DECODER_MASK): defined. + (ECONV_ENCODER_MASK): defined. + + * io.c (make_writeconv): restrict ecflags for writeconv with + ECONV_ERROR_HANDLER_MASK. + Sat Sep 6 23:03:41 2008 Tanaka Akira * include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 7a616a1934..d78ef11dc1 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -250,27 +250,32 @@ VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytes void rb_econv_binmode(rb_econv_t *ec); /* flags for rb_econv_open */ -#define ECONV_INVALID_MASK 0x000f -#define ECONV_INVALID_REPLACE 0x0002 -#define ECONV_UNDEF_MASK 0x00f0 -#define ECONV_UNDEF_REPLACE 0x0020 -#define ECONV_UNDEF_HEX_CHARREF 0x0030 +#define ECONV_ERROR_HANDLER_MASK 0x000000ff + +#define ECONV_INVALID_MASK 0x0000000f +#define ECONV_INVALID_REPLACE 0x00000002 + +#define ECONV_UNDEF_MASK 0x000000f0 +#define ECONV_UNDEF_REPLACE 0x00000020 +#define ECONV_UNDEF_HEX_CHARREF 0x00000030 /* usable only if destination encoding is ascii compatible */ -#define ECONV_UNIVERSAL_NEWLINE_DECODER 0x0100 +#define ECONV_DECODER_MASK 0x00000f00 +#define ECONV_UNIVERSAL_NEWLINE_DECODER 0x00000100 /* usable only if source encoding is ascii compatible */ -#define ECONV_CRLF_NEWLINE_ENCODER 0x0200 -#define ECONV_CR_NEWLINE_ENCODER 0x0400 -#define ECONV_XML_TEXT_ENCODER 0x0800 -#define ECONV_XML_ATTR_ENCODER 0x1000 +#define ECONV_ENCODER_MASK 0x0000f000 +#define ECONV_CRLF_NEWLINE_ENCODER 0x00001000 +#define ECONV_CR_NEWLINE_ENCODER 0x00002000 +#define ECONV_XML_TEXT_ENCODER 0x00004000 +#define ECONV_XML_ATTR_ENCODER 0x00008000 /* end of flags for rb_econv_open */ /* flags for rb_econv_convert */ -#define ECONV_PARTIAL_INPUT 0x10000 -#define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x20000 +#define ECONV_PARTIAL_INPUT 0x00010000 +#define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x00020000 /* end of flags for rb_econv_convert */ #endif /* RUBY_ENCODING_H */ diff --git a/io.c b/io.c index 88217efe0a..ac7c1f16b5 100644 --- a/io.c +++ b/io.c @@ -716,6 +716,7 @@ make_writeconv(rb_io_t *fptr) if (NEED_NEWLINE_ENCODER(fptr)) fptr->writeconv_pre_ecflags |= TEXTMODE_NEWLINE_ENCODER; #endif + ecflags &= ECONV_ERROR_HANDLER_MASK; enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc; senc = rb_econv_stateless_encoding(enc->name); diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 0dd790f60d..9d999be59e 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -1459,5 +1459,27 @@ EOT } end + def test_w_xml_attr + with_tmpdir { + open("eucjp.txt", "w:euc-jp:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("eucjp.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"\x8F\xB0\xA1\"".force_encoding("ascii-8bit"), content) + + open("sjis.txt", "w:sjis:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("sjis.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"丂\"".force_encoding("ascii-8bit"), content) + + open("iso-2022-jp.txt", "w:iso-2022-jp:utf-8", xml: :attr) {|f| + f.print "\u4E02" # U+4E02 is 0x3021 in JIS X 0212 + } + content = File.read("iso-2022-jp.txt", :mode=>"rb:ascii-8bit") + assert_equal("\"丂\"".force_encoding("ascii-8bit"), content) + } + end + end