From 1524572ce96fcef2871b2dcda3eaf3161b2b8469 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 2 Dec 2007 13:08:03 +0000 Subject: * parse.y (parser_tokadd_mbchar): fix for ASCII chars. [ruby-dev:32432] * parse.y (parser_parse_string, parser_here_document): prevent false error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 6e67fd92d2..12d2e8893b 100644 --- a/parse.y +++ b/parse.y @@ -5304,7 +5304,7 @@ static int parser_tokadd_mbchar(struct parser_params *parser, int c) { int len = parser_mbclen(); - if (lex_p + len > lex_pend) { + if (len <= 0 || lex_p + len - 1 > lex_pend) { compile_error(PARSER_ARG "illegal multibyte char"); return -1; } @@ -5491,11 +5491,13 @@ parser_parse_string(struct parser_params *parser, NODE *quote) &enc) == -1) { ruby_sourceline = nd_line(quote); if (func & STR_FUNC_REGEXP) { - compile_error(PARSER_ARG "unterminated regexp meets end of file"); + if (parser->eofp) + compile_error(PARSER_ARG "unterminated regexp meets end of file"); return tREGEXP_END; } else { - compile_error(PARSER_ARG "unterminated string meets end of file"); + if (parser->eofp) + compile_error(PARSER_ARG "unterminated string meets end of file"); return tSTRING_END; } } @@ -5625,6 +5627,7 @@ parser_here_document(struct parser_params *parser, NODE *here) if ((c = nextc()) == -1) { error: compile_error(PARSER_ARG "can't find string \"%s\" anywhere before EOF", eos); + restore: heredoc_restore(lex_strterm); lex_strterm = 0; return 0; @@ -5678,8 +5681,10 @@ parser_here_document(struct parser_params *parser, NODE *here) } do { pushback(c); - if ((c = tokadd_string(func, '\n', 0, NULL, - &enc)) == -1) goto error; + if ((c = tokadd_string(func, '\n', 0, NULL, &enc)) == -1) { + if (parser->eofp) goto error; + goto restore; + } if (c != '\n') { set_yylval_str(STR_NEW3(tok(), toklen(), enc, func)); return tSTRING_CONTENT; -- cgit v1.2.3