Note that there are some explanatory texts on larger screens.

plurals
  1. PO"invalid byte sequence in UTF-8" in rspec controller response
    text
    copied!<p>We encounter the said error on some of our newer virtual machines, while other machines remain unaffected and wonder why and furthermore how to get rid of them.</p> <p>the two main differences are as follows</p> <pre><code>vm_old: debian squeeze ruby1.9.2p0 vm_new: debian wheezy ruby1.9.2p320 (over rvm) </code></pre> <p>There naturally are more changes within the VMs, but i don't know which would affect this behavior.</p> <p>We have a response containing umlauts within some of our controllers (ie. '{"message": "ü"}') and we have set <code># encoding: utf-8</code></p> <p>Within the spec we test the response against a fixed string with this umlaut</p> <pre><code>it 'should test something' do get :some_controller, format: :json response.status.should == 200 json = ActiveSupport::JSON.decode(response.body) json["message"].should == 'ü' # breaks on this line # ... some more tests end </code></pre> <p>The substitute for ü seems to be a random 4 digit string. On occasion this string seems to be valid utf-8 and can be transfered. We then have a failed spec instead of the error message in the title, since the random string is not the same as ü.</p> <p>The spec file itself also has the <code># encoding: utf-8</code> on the first line. We tried playing with the locale or with <code>force_encoding('utf-8')</code></p> <p>The question now becomes: Has someone else encountered a problem like this? and How to solve it?</p> <p><strong>Edit</strong>: turns out it is not always starting with <code>P\</code>.</p> <p><strong>Edit 2</strong>: Testing around showed it is a problem with the json decode. The controller response is something like <code>"{\"foo\": \"\u00fc\"}"</code>, decoding that results in random output where the sequence <code>\u00fc</code> used to be.</p> <p>for simple reproduction:</p> <pre><code>bundle exec rails c &gt; ActiveSupport::JSON.decode(ActiveSupport::JSON.encode({:foo =&gt; "ü"}) </code></pre> <p>rails version is 3.0.4</p> <p><strong>Edit 3</strong>: Changing the JSON backend to Yaml seems to be a valid workaround.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload