spring
spring copied to clipboard
4.3.0: Spring-enabled binstub crashes if ENV contains non-ASCII value
This bug was introduced in spring 4.3.0.
If the shell environment contains a non-ASCII value, e.g.
export HOMEBREW_INSTALL_BADGE=🍵
Then running a spring-enabled binstub like bin/rspec crashes with an Encoding::CompatibilityError error:
$ bin/rspec spec/example_spec.rb
gems/spring-4.3.0/lib/spring/json.rb:382:in 'String#[]=': incompatible character encodings: UTF-8 and BINARY (ASCII-8BIT) (Encoding::CompatibilityError)
from gems/spring-4.3.0/lib/spring/json.rb:382:in 'Spring::OkJson#unquote'
from gems/spring-4.3.0/lib/spring/json.rb:306:in 'Spring::OkJson#strtok'
from gems/spring-4.3.0/lib/spring/json.rb:272:in 'Spring::OkJson#tok'
from gems/spring-4.3.0/lib/spring/json.rb:235:in 'Spring::OkJson#lex'
from gems/spring-4.3.0/lib/spring/json.rb:66:in 'Spring::OkJson#decode'
from gems/spring-4.3.0/lib/spring/json.rb:16:in 'Spring::JSON.load'
from gems/spring-4.3.0/lib/spring/application.rb:185:in 'Spring::Application#serve'
from gems/spring-4.3.0/lib/spring/application.rb:158:in 'block in Spring::Application#run'
from <internal:kernel>:168:in 'Kernel#loop'
from gems/spring-4.3.0/lib/spring/application.rb:152:in 'Spring::Application#run'
from gems/spring-4.3.0/lib/spring/application/boot.rb:25:in '<top (required)>'
from <internal:rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
from <internal:rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
from -e:1:in '<main>'
Downgrading to spring 4.2.1 fixes the problem.
My setup:
- spring 4.3.0
- rails 7.2.2.1 (7-2-stable
27d728e3464c) - ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
I am seeing this as well. My traceback:
/Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:382:in `[]=': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:382:in `unquote'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:306:in `strtok'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:272:in `tok'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:235:in `lex'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:66:in `decode'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/json.rb:16:in `load'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/application.rb:185:in `serve'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/application.rb:158:in `block in run'
from <internal:kernel>:187:in `loop'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/application.rb:152:in `run'
from /Users/jacquelinechenault/.rvm/gems/ruby-3.3.1/gems/spring-4.3.0/lib/spring/application/boot.rb:25:in `<top (required)>'
from <internal:/Users/jacquelinechenault/.rvm/rubies/ruby-3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
from <internal:/Users/jacquelinechenault/.rvm/rubies/ruby-3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
from -e:1:in `<main>'
My setup: spring 4.3.0 rails 7.1.5.1 ruby 3.3.1 & 3.3.7 (I was in the middle of upgrading an app ruby version when this came up)
My current solve was to run:
printenv | perl -ne 'print if /[^[:ascii:]]/' to find the env var with a noncompliant value, then change the problematic envar to something less problematic (in my case, it was an ascii character I had in my PS1 env var)
Fixed by #738