Project

General

Profile

Actions

Bug #5262

closed

invalid multibyte escapes should raise a clearer error

Added by coldnebo (Larry Kyrala) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
Backport:
[ruby-core:39222]

Description

Here's an irb example of the issue using 'curly-quotes':

ruby-1.9.2-p290 :001 > "“"
=> "“"
ruby-1.9.2-p290 :002 > "“".encoding
=> #Encoding:UTF-8
ruby-1.9.2-p290 :003 > "\“"
SyntaxError: (irb):3: invalid multibyte char (UTF-8)
(irb):3: invalid multibyte char (UTF-8)
from /local/rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `'

I don't think anyone would ever do this on purpose. But it can happen accidentally when copying and pasting snippets from email/text clients.

Trying to spot this error can be very difficult because curly quotes are valid UTF-8 chars in this case.

I propose that the error be changed to:

SyntaxError: (irb):3: invalid escape sequence: '\“'.

This would have directed me to the root cause of the problem much sooner.

background on the original rails context here: https://gist.github.com/1184533

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

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

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


  • parse.y (parser_tokadd_string, parser_yylex): ignore a backslash
    which prefixes an non-ascii character, which has no escape
    syntax. [ruby-core:39222] [Ruby 1.9 - Bug #5262]

Updated by nagarajpg (Nagaraj G) over 12 years ago

Hi,

This issue is not yet fixed ! I am getting the same error message in 1.9.3p0.

[akshatha@localhost chiliproject]$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

[akshatha@localhost chiliproject]$ rails -v
Rails 2.3.14

Application: Chiliproject 3.0.0beta + haltr plugin

Processing InvoicesController#index (for 127.0.0.1 at 2012-01-07 00:19:57) [GET]
Parameters: {"controller"=>"invoices", "action"=>"index", "id"=>"test-project"}
Rendering template within layouts/haltr
Rendering invoices/index
Completed in 212ms (View: 76, DB: 13) | 200 OK [http://0.0.0.0/invoices/index/test-project]
Error during failsafe response: "\xE2" on US-ASCII
[2012-01-07 00:20:01] ERROR NoMethodError: undefined method each' for nil:NilClass
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:324:ininitialize'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:318:in new'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:318:innew'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/content_length.rb:14:in call'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/handler/webrick.rb:48:inservice'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:inrun'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Thanks
Nagaraj

Updated by naruse (Yui NARUSE) over 12 years ago

Nagaraj G wrote:

This issue is not yet fixed ! I am getting the same error message in 1.9.3p0.

[akshatha@localhost chiliproject]$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

[akshatha@localhost chiliproject]$ rails -v
Rails 2.3.14

Application: Chiliproject 3.0.0beta + haltr plugin

Processing InvoicesController#index (for 127.0.0.1 at 2012-01-07 00:19:57) [GET]
Parameters: {"controller"=>"invoices", "action"=>"index", "id"=>"test-project"}
Rendering template within layouts/haltr
Rendering invoices/index
Completed in 212ms (View: 76, DB: 13) | 200 OK [http://0.0.0.0/invoices/index/test-project]
Error during failsafe response: "\xE2" on US-ASCII
[2012-01-07 00:20:01] ERROR NoMethodError: undefined method each' for nil:NilClass
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:324:ininitialize'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:318:in new'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/utils.rb:318:innew'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/content_length.rb:14:in call'
/home/akshatha/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.1.3/lib/rack/handler/webrick.rb:48:inservice'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:inrun'
/home/akshatha/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

It seems different problem, and maybe chiliproject's issue.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0