stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

Encoding changes from UTF-8 to ASCII-8BIT #202

Closed asgerb closed 3 years ago

asgerb commented 4 years ago

Bug Report

Using StimulusReflex in my app caused ActiveSupport::Inflector.transliterate to throw a strange error:

StimulusReflex::Channel Failed to re-render http://localhost:3000/Buy Can not transliterate strings with ASCII-8BIT encoding .../activesupport-6.0.3/lib/active_support/inflector/transliterate.rb:67:in `transliterate'

I changed this line to return the full stack trace, instead of just the first line (maybe it would be nice to make this configurable for debugging purposes?). After which I found the origin of the error – the following code I had in a helper method: action_name.parameterize.

Basically the string returned by action_name changes its encoding between the initial request and the stimulus reflex morphing. I'm guessing this is due to the way the controller is called, or perhaps it's really a bug in Rails?

This actually led me to realize that I don't need the .parameterize, but I wanted to submit this bug report in any case, as it might cause other unforeseen bugs down the road?

Describe the bug

The encoding of the string returned by action_name (possibly others as well) changes from UTF-8 to ASCII-8BIT between the initial request and the stimulus reflex morph.

To Reproduce

Using the TodoMVC

  1. Add <%= action_name.encoding %> to the beginning of the <body> tag in app/views/layouts/application.html.erb
  2. Boot up the app, the page will read UTF-8
  3. Add a todo, the page will now read ASCII-8BIT

Expected behavior

The encoding should ideally stay the same (UTF-8) between requests.

Versions

StimulusReflex

External tools

scottbarrow commented 4 years ago

Is this maybe due to rendering (and subsequently morphing) a string that comes from params encoded ASCII-8BIT?