1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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. 



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-06 15:39:00 +00:00
parent dd27b8f457
commit 0508672f0e
4 changed files with 49 additions and 12 deletions

View file

@ -1,3 +1,12 @@
Sun Sep 7 00:37:25 2008 Tanaka Akira <akr@fsij.org>
* 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 <akr@fsij.org> Sat Sep 6 23:03:41 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from * include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from

View file

@ -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); void rb_econv_binmode(rb_econv_t *ec);
/* flags for rb_econv_open */ /* flags for rb_econv_open */
#define ECONV_INVALID_MASK 0x000f
#define ECONV_INVALID_REPLACE 0x0002
#define ECONV_UNDEF_MASK 0x00f0 #define ECONV_ERROR_HANDLER_MASK 0x000000ff
#define ECONV_UNDEF_REPLACE 0x0020
#define ECONV_UNDEF_HEX_CHARREF 0x0030 #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 */ /* 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 */ /* usable only if source encoding is ascii compatible */
#define ECONV_CRLF_NEWLINE_ENCODER 0x0200 #define ECONV_ENCODER_MASK 0x0000f000
#define ECONV_CR_NEWLINE_ENCODER 0x0400 #define ECONV_CRLF_NEWLINE_ENCODER 0x00001000
#define ECONV_XML_TEXT_ENCODER 0x0800 #define ECONV_CR_NEWLINE_ENCODER 0x00002000
#define ECONV_XML_ATTR_ENCODER 0x1000 #define ECONV_XML_TEXT_ENCODER 0x00004000
#define ECONV_XML_ATTR_ENCODER 0x00008000
/* end of flags for rb_econv_open */ /* end of flags for rb_econv_open */
/* flags for rb_econv_convert */ /* flags for rb_econv_convert */
#define ECONV_PARTIAL_INPUT 0x10000 #define ECONV_PARTIAL_INPUT 0x00010000
#define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x20000 #define ECONV_OUTPUT_FOLLOWED_BY_INPUT 0x00020000
/* end of flags for rb_econv_convert */ /* end of flags for rb_econv_convert */
#endif /* RUBY_ENCODING_H */ #endif /* RUBY_ENCODING_H */

1
io.c
View file

@ -716,6 +716,7 @@ make_writeconv(rb_io_t *fptr)
if (NEED_NEWLINE_ENCODER(fptr)) if (NEED_NEWLINE_ENCODER(fptr))
fptr->writeconv_pre_ecflags |= TEXTMODE_NEWLINE_ENCODER; fptr->writeconv_pre_ecflags |= TEXTMODE_NEWLINE_ENCODER;
#endif #endif
ecflags &= ECONV_ERROR_HANDLER_MASK;
enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc; enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc;
senc = rb_econv_stateless_encoding(enc->name); senc = rb_econv_stateless_encoding(enc->name);

View file

@ -1459,5 +1459,27 @@ EOT
} }
end 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("\"&#x4E02;\"".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("\"&#x4E02;\"".force_encoding("ascii-8bit"), content)
}
end
end end