Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexpError: invalid multibyte character #2528

nbroyles opened this issue Jan 27, 2015 · 1 comment

RegexpError: invalid multibyte character #2528

nbroyles opened this issue Jan 27, 2015 · 1 comment


Copy link

@nbroyles nbroyles commented Jan 27, 2015

Seeing the following error when attempting to run .sub on a US-ASCII string with a UTF-8 encoded argument string that has a non-ASCII character:


1.9.3-p547 :001 > str = 9999.to_s
 => "9999"
1.9.3-p547 :002 > str.encoding
 => #<Encoding:US-ASCII>
1.9.3-p547 :003 > str.sub("¥", "")
 => "9999"


jruby-1.7.18 :002 > str = 9999.to_s
 => "9999"
jruby-1.7.18 :003 > str.encoding
 => #<Encoding:US-ASCII>
jruby-1.7.18 :005 > str.sub("¥", "")
RegexpError: invalid multibyte character: /Â¥/
    from org/jruby/ `sub!'
    from org/jruby/ `sub'
    from (irb):5:in `evaluate'
    from org/jruby/ `eval'
    from org/jruby/ `loop'
    from org/jruby/ `catch'
    from org/jruby/ `catch'
    from /Users/nb/.rvm/gems/jruby-1.7.18/bundler/gems/rails-fc40cbbc4aaa/railties/lib/rails/commands/console.rb:110:in `start'
    from /Users/nb/.rvm/gems/jruby-1.7.18/bundler/gems/rails-fc40cbbc4aaa/railties/lib/rails/commands/console.rb:9:in `start'
    from /Users/nb/.rvm/gems/jruby-1.7.18/bundler/gems/rails-fc40cbbc4aaa/railties/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/nb/.rvm/gems/jruby-1.7.18/bundler/gems/rails-fc40cbbc4aaa/railties/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/nb/.rvm/gems/jruby-1.7.18/bundler/gems/rails-fc40cbbc4aaa/railties/lib/rails/commands.rb:17:in `(root)'
    from org/jruby/ `require'
    from script/rails:1:in `(root)'

JRuby version info:

jruby-1.7.18 :006 > `jruby -v`
 => "jruby 1.7.18 (1.9.3p551) 2014-12-22 625381c on Java HotSpot(TM) 64-Bit Server VM 1.8.0-b132 [darwin-x86_64]\n"

This is relevant as it manifests itself in the Ruby Money gem at the following location:

Copy link

@enebo enebo commented Jan 28, 2015

cherry-picked to master. Closing. For posterity MRI does not use regexps for string subs and has this dual-use loop where search and replace code is calls either regexp or string stuff. It was pretty invasive to do it that way and it seemed kind of difficult to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants