ruby-changes:72917
From: Nobuyoshi <ko1@a...>
Date: Fri, 12 Aug 2022 15:58:28 +0900 (JST)
Subject: [ruby-changes:72917] 844a0edbae (master): [Bug #18962] Do not read again once reached EOF
https://git.ruby-lang.org/ruby.git/commit/?id=844a0edbae From 844a0edbae6e74293e3d0cb1ceeeb66a4371d06d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 11 Aug 2022 22:24:47 +0900 Subject: [Bug #18962] Do not read again once reached EOF `Ripper::Lexer#parse` re-parses the source code with syntax errors when `raise_errors: false`. Co-Authored-By: tompng <tomoyapenguin@g...> --- parse.y | 1 + test/ripper/test_lexer.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/parse.y b/parse.y index b4c3106b8c..d0f37a18cc 100644 --- a/parse.y +++ b/parse.y @@ -9299,6 +9299,7 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9299 case '\004': /* ^D */ case '\032': /* ^Z */ case -1: /* end of script. */ + p->eofp = 1; return 0; /* white spaces */ diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index 83130668be..4f3f4657ef 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -100,6 +100,20 @@ class TestRipper::Lexer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_lexer.rb#L100 assert_equal expect, Ripper.lex(src).map {|e| e[1]} end + def test_end_of_script_char + all_assertions do |all| + ["a", %w"[a ]", %w"{, }", "if"].each do |src, append| + expected = Ripper.lex(src).map {|e| e[1]} + ["\0b", "\4b", "\32b"].each do |eof| + c = "#{src}#{eof}#{append}" + all.for(c) do + assert_equal expected, Ripper.lex(c).map {|e| e[1]} + end + end + end + end + end + def test_slice assert_equal "string\#{nil}\n", Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/