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

* parse.y (parser_tokadd_utf8, parser_tokadd_string): allow NUL

containing symbol literals, as well as String#to_sym.
  [ruby-dev:41447]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-05-29 18:40:48 +00:00
parent 6cb380e698
commit 106b437ceb
4 changed files with 22 additions and 27 deletions

View file

@ -1,3 +1,9 @@
Sun May 30 03:40:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parser_tokadd_utf8, parser_tokadd_string): allow NUL
containing symbol literals, as well as String#to_sym.
[ruby-dev:41447]
Sun May 30 02:21:34 2010 Yusuke Endoh <mame@tsg.ne.jp> Sun May 30 02:21:34 2010 Yusuke Endoh <mame@tsg.ne.jp>
* ext/zlib/zlib.c (zstream_append_input2): add RB_GC_GUARD. * ext/zlib/zlib.c (zstream_append_input2): add RB_GC_GUARD.

15
parse.y
View file

@ -5487,11 +5487,6 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp,
if (string_literal) tokaddmbc(codepoint, *encp); if (string_literal) tokaddmbc(codepoint, *encp);
} }
else if (string_literal) { else if (string_literal) {
if (codepoint == 0 && symbol_literal) {
yyerror("symbol cannot contain '\\u{0}'");
return 0;
}
tokadd(codepoint); tokadd(codepoint);
} }
} while (string_literal && (peek(' ') || peek('\t'))); } while (string_literal && (peek(' ') || peek('\t')));
@ -5519,11 +5514,6 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp,
if (string_literal) tokaddmbc(codepoint, *encp); if (string_literal) tokaddmbc(codepoint, *encp);
} }
else if (string_literal) { else if (string_literal) {
if (codepoint == 0 && symbol_literal) {
yyerror("symbol cannot contain '\\u0000'");
return 0;
}
tokadd(codepoint); tokadd(codepoint);
} }
} }
@ -5883,11 +5873,6 @@ parser_tokadd_string(struct parser_params *parser,
pushback(c); pushback(c);
break; break;
} }
if (!c && (func & STR_FUNC_SYMBOL)) {
func &= ~STR_FUNC_SYMBOL;
compile_error(PARSER_ARG "symbol cannot contain '\\0'");
continue;
}
if (c & 0x80) { if (c & 0x80) {
has_nonascii = 1; has_nonascii = 1;
if (enc != *encp) { if (enc != *encp) {

View file

@ -491,14 +491,16 @@ class TestParse < Test::Unit::TestCase
end end
def test_symbol def test_symbol
assert_raise(SyntaxError) do bug = '[ruby-dev:41447]'
eval ":'foo\0bar'" sym = "foo\0bar".to_sym
assert_nothing_raised(SyntaxError, bug) do
assert_equal(sym, eval(":'foo\0bar'"))
end end
assert_raise(SyntaxError) do assert_nothing_raised(SyntaxError, bug) do
eval ':"foo\u0000bar"' assert_equal(sym, eval(':"foo\u0000bar"'))
end end
assert_raise(SyntaxError) do assert_nothing_raised(SyntaxError, bug) do
eval ':"foo\u{0}bar"' assert_equal(sym, eval(':"foo\u{0}bar"'))
end end
assert_raise(SyntaxError) do assert_raise(SyntaxError) do
eval ':"foo\u{}bar"' eval ':"foo\u{}bar"'

View file

@ -57,12 +57,14 @@ EOS
assert_equal(:"\u{41}", :"\u0041") assert_equal(:"\u{41}", :"\u0041")
assert_equal(:ü, :"\u{fc}") assert_equal(:ü, :"\u{fc}")
# the NUL character is not allowed in symbols # the NUL character is allowed in symbols
assert_raise(SyntaxError) { eval %q(:"\u{0}")} bug = '[ruby-dev:41447]'
assert_raise(SyntaxError) { eval %q(:"\u0000")} sym = "\0".to_sym
assert_raise(SyntaxError) { eval %q(:"\u{fc 0 0041}")} assert_nothing_raised(SyntaxError, bug) {assert_equal(sym, eval(%q(:"\u{0}")))}
assert_raise(SyntaxError) { eval %q(:"\x00")} assert_nothing_raised(SyntaxError, bug) {assert_equal(sym, eval(%q(:"\u0000")))}
assert_raise(SyntaxError) { eval %q(:"\0")} assert_nothing_raised(SyntaxError, bug) {assert_equal("\u{fc}\0A".to_sym, eval(%q(:"\u{fc 0 0041}")))}
assert_nothing_raised(SyntaxError, bug) {assert_equal(sym, eval(%q(:"\x00")))}
assert_nothing_raised(SyntaxError, bug) {assert_equal(sym, eval(%q(:"\0")))}
end end
def test_regexp def test_regexp