Third Time’s the Charm?
Rails got updated to 2.3.6, 2.3.7, and 2.3.8, within the space of 48 hours. On the theory that the “Third time’s the charm.” I decided to update Instiki for 2.3.8, this morning.
Running the Instiki test suite, immediately pointed to some problems.
Under Ruby 1.9.x, I got a slew of errors that looked like:
test_accept_header_html(ApplicationTest):
ArgumentError: invalid byte sequence in US-ASCII
/Users/distler/instiki/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `=~'
/Users/distler/instiki/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `!~'
/Users/distler/instiki/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb:68:in `blank?'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/response.rb:201:in `nonempty_ok_response?'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/response.rb:187:in `handle_conditional_get!'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/response.rb:140:in `prepare!'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/base.rb:540:in `send_response'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/base.rb:534:in `process'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_with_filters'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/test_process.rb:567:in `process_with_test'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/test_process.rb:447:in `process'
/Users/distler/instiki/vendor/rails/actionpack/lib/action_controller/test_process.rb:398:in `get'
test/functional/application_test.rb:48:in `test_accept_header_html'
/usr/local/lib/ruby/gems/1.9.1/gems/mocha-0.9.8/lib/mocha/integration/mini_test/version_131_and_above.rb:26:in `run'
/Users/distler/instiki/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:24:in `run'
US-ASCII ?? Well, it turns out that activesupport/lib/active_support/core_ext/object/blank.rb
defines an extension to the String
class, without being sufficiently (at least, for Ruby 1.9) picky about encodings. The solution was to add an encoding-aware monkey-patch to lib/stringsupport.rb.
class String ... def blank? self.dup.as_bytes !~ /\S/ end end
Similarly, I had some problems with ERB templates
test_search_FFFD_in_query(WikiControllerTest):
ActionView::TemplateError: incompatible character encodings: UTF-8 and US-ASCII
On line #70 of app/views/layouts/default.rhtml
67: <div class="errorExplanation"><%= escape_preserving_linefeeds(@error || flash[:error]) %></div>
68: <%- end -%>
69:
70: <%= @content_for_layout %>
71:
72: <%- if @show_footer -%>
73: <div id="footer">
Again, this was a matter of Rails trying to guess the encoding of the ERB templates, and guessing wrong (US-ASCII). One solution would be to go through all the ERB templates, and set the encoding manually. I decided on a simpler alternative of a monkey patch, overriding the guessing code in actionpack/lib/action_view/template_handlers/erb.rb
, and forcing the encoding to ‘UTF-8’.
The other annoyance was that, apparently, X-Sendfile no longer works in development mode, which broke my tests to … umh … check that X-Sendfile works.
Finally, it seems that the “Rails 3.0” XSS Protection is enabled by default. Which meant fixing various helper methods, to mark their output as html_safe
.
Other than that, my morning was OK …
Hope this helps someone else spend their day more productively.
Update:
As Sam points out in the comments, in response to this post the Rails team have modified Rails 2.3.x to ensure that the XSS Protection really is disabled by default. If you’re upgrading a Rails app from 2.3.5, and want to save yourself some trouble, you might want to download that patch (or wait for 2.3.9).Being a masochist, I went the other direction and installed the rails_xss plugin to see what else would break.
Re: Third Time’s the Charm?
Does this commit help?