Skip to content

Commit

Permalink
Do not warn CR inside string literal
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 4, 2020
1 parent 7a51d97 commit 9cdc964
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 8 additions & 6 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -6260,11 +6260,6 @@ parser_cr(struct parser_params *p, int c)
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;
}

Expand Down Expand Up @@ -8833,7 +8828,14 @@ parser_yylex(struct parser_params *p)
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
Expand Down
9 changes: 7 additions & 2 deletions test/ruby/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,14 @@ def test__END___cr

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
Expand Down

0 comments on commit 9cdc964

Please sign in to comment.