Project

General

Profile

Actions

Backport #8375

closed

Lexer error when specific character sequence occurs in string literals

Added by dimitri-lo2u (Dimitri Geshef) almost 11 years ago. Updated over 10 years ago.

Status:
Closed
[ruby-core:54846]

Description

The next line causes lexer/parser error:

problematic_string = "#$%"

The error message is: unterminated string meets end of file

The bug occurs in MRI1.9.3... ruby -v = ruby 1.9.3p374 (2013-01-15) [i386-mingw32]

... and in 2.0.0 ruby -v = ruby 2.0.0p0 (2013-02-24) [i386-mingw32]

Updated by Eregon (Benoit Daloze) almost 11 years ago

The complete error is:

$ ruby -e 'problematic_string = "#$%"'
-e:1: syntax error, unexpected $undefined
problematic_string = "#$%"
^
-e:1: unterminated string meets end of file

So this is because it expects a global named $% but this is an invalid global name.

followed by (@@ or @ or $) is interpolating the following variable in double-quoted strings.

It would be nice if the error message could be clearer.

(I personally dislike the special syntax for # (@@ or @ or $) instead of plain #{expr},
it leads to weird cases with $" ($LOADED_FEATURES): "#$" and "#$"").

It can be avoided by using "#$%" or using simple quotes as '#$%'.

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40607.
Dimitri, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


parse.y: fail if invalid name

  • parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid
    name character. [ruby-core:54846] [Bug #8375].
Actions #3

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to nagachika (Tomoyuki Chikanaga)

Updated by matz (Yukihiro Matsumoto) almost 11 years ago

I'd like to treat them as mere strings rather than errors.

Matz.

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Assignee changed from nagachika (Tomoyuki Chikanaga) to nobu (Nobuyoshi Nakada)

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to nagachika (Tomoyuki Chikanaga)

add r40635 for backport.

Actions #7

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40650.
Dimitri, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40606,40607,40635: [Backport #8375]

test_scanner_events.rb: assert_location

* test/ripper/test_scanner_events.rb (TestRipper#assert_location):

rename so skipped in backtraces.
* parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid
name character. [ruby-core:54846] [Bug #8375].

* parse.y (parser_peek_variable_name): treat invalid global, class,
  and instance variable names as mere strings rather than errors.
  [ruby-core:54885] [Bug #8375]

Updated by sakuro (Sakuro OZAWA) over 10 years ago

=begin
# The bug occurs in MRI1.9.3... ruby -v = ruby 1.9.3p374 (2013-01-15) [i386-mingw32]

Is this to be backported to 1.9.3?
=end

Actions #9

Updated by nagachika (Tomoyuki Chikanaga) over 10 years ago

  • Project changed from Backport200 to Backport193
  • Status changed from Closed to Assigned
  • Assignee changed from nagachika (Tomoyuki Chikanaga) to usa (Usaku NAKAMURA)

Thanks you for your notice! I move this ticket to Backport93.
usa-san will make a judgement about it.

Actions #10

Updated by usa (Usaku NAKAMURA) over 10 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r42462.
Dimitri, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40606,40607,40635: [Backport #8375]

test_scanner_events.rb: assert_location

* test/ripper/test_scanner_events.rb (TestRipper#assert_location):

rename so skipped in backtraces.
* parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid
name character. [ruby-core:54846] [Bug #8375].

* parse.y (parser_peek_variable_name): treat invalid global, class,
  and instance variable names as mere strings rather than errors.
  [ruby-core:54885] [Bug #8375]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0