ruby-changes:59921
From: Nobuyoshi <ko1@a...>
Date: Tue, 4 Feb 2020 14:54:22 +0900 (JST)
Subject: [ruby-changes:59921] 9cdc964d07 (master): Do not warn CR inside string literal
https://git.ruby-lang.org/ruby.git/commit/?id=9cdc964d07 From 9cdc964d075fc3d21b8ce8456ac88f57a5183ec0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 4 Feb 2020 14:41:52 +0900 Subject: Do not warn CR inside string literal diff --git a/parse.y b/parse.y index c0d4639..11ef0f7 100644 --- a/parse.y +++ b/parse.y @@ -6260,11 +6260,6 @@ parser_cr(struct parser_params *p, int c) https://github.com/ruby/ruby/blob/trunk/parse.y#L6260 p->lex.pcur++; c = '\n'; } - else if (!p->cr_seen) { - p->cr_seen = TRUE; - /* carried over with p->lex.nextline for nextc() */ - rb_warn0("encountered \\r in middle of line, treated as a mere space"); - } return c; } @@ -8833,7 +8828,14 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L8828 return 0; /* white spaces */ - case ' ': case '\t': case '\f': case '\r': + case '\r': + if (!p->cr_seen) { + p->cr_seen = TRUE; + /* carried over with p->lex.nextline for nextc() */ + rb_warn0("encountered \\r in middle of line, treated as a mere space"); + } + /* fall through */ + case ' ': case '\t': case '\f': case '\13': /* '\v' */ space_seen = 1; #ifdef RIPPER diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 5591b7c..f92966f 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -949,9 +949,14 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L949 def test_warning_for_cr feature8699 = '[ruby-core:56240] [Feature #8699]' - assert_warning(/encountered \\r/, feature8699) do - eval("\r""__id__\r") + s = assert_warning(/encountered \\r/, feature8699) do + eval("'\r'\r") end + assert_equal("\r", s) + s = assert_warning('') do + eval("'\r'\r\n") + end + assert_equal("\r", s) end def test_unexpected_fraction -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/