Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 10/7/2009

Mike Grafton
Wednesday, October 7, 2009

Interesting

String#to_xs behavior can change if you happen to have the fast_xs gem installed.

Rails tries to require the ‘fast_xs’ c-extension to implement String#to_xs (it falls back to a pure Ruby XML escaping algorithm if it can’t find it). Unfortunately, fast_xs is not API compatible with the built-in version provided by Rails (it escapes double quotes, for no apparent reason).

This is all well and good if that’s what you decide go with. But unfortunately, fast_xs is a c-extension, which means that if it’s been installed on your system for whatever reason (say, installing Hpricot), then Rails will start using it, and there’s no good way to turn it off (unless you consider hacking your ActiveSupport gem “good”). So the behavior of your app could change without any explicit intention on your part.

fast_xs also exists as a gem that wraps the c-extension, and if you use to_xs (i.e. your app emits XML), it might behoove you to depend on the gem explicitly. It was noted that for apps that emit a lot of XML to be performant, you will need fast_xs, anyway.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

5 Comments

  1. Adam Milligan says:

    Interestingly, it turns out that JRuby has yet a third implementation of #fast_xs which will escape the XML differently than both the ActiveSupport ruby implementation of #to_xs and the fast_xs C extension.

    In summary:
    #to_xs (ActiveSupport): escapes < , >, and &
    #fast_xs (C): escapes < , >, &, and ”
    #fast_xs (JRuby): escapes < , >, &, “, and ‘ (and possibly others)

    As with the C version, if you’re using JRuby you get the JRuby version whether you like it or not.

    October 7, 2009 at 4:23 pm

  2. Adam Milligan says:

    Grrr, markdown.

    * #to_xs (ActiveSupport): escapes < , >, and &
    * #fast_xs (C): escapes < , >, &, and ”
    * #fast_xs (JRuby): escapes < , >, &, “, and ‘ (and possibly others)

    October 7, 2009 at 4:24 pm

  3. Adam Milligan says:

    To be clear, the Java implementation of #fast_xs comes from Hpricot, not from JRuby itself. Installing the Hpricot gem using JRuby brings in the hpricot-java library, which has the not-consistent-with-anything-else implementation of #fast_xs.

    October 7, 2009 at 6:21 pm

  4. Mislav says:

    Coworker and I just spent 3 hours trying to figure out why is our Rails loading activating the Hpricot 0.8.1 gem without us specifying it.

    We pinpointed fast_xs by augmenting `Gem.activate` method to raise an error whenever it tries to activate the ‘hpricot’ gem. This left me wondering is there a more graceful method to debugging such load issues.

    October 8, 2009 at 6:17 am

  5. Chad Woolley says:

    @mislav – I first try using RubyGems reverse dependency command:

    gem dependency -R hpricot

    That will tell you what depends on hpricot. Sometimes this is difficult, though, especially if there is a long dependency chain.

    October 20, 2009 at 1:17 pm

Add New Comment Cancel reply

Your email address will not be published.

Mike Grafton

Mike Grafton
San Francisco

Recent Posts

  • SF Standup 5/6/2011: Bundler Blah Blah Blah Blah
  • SF Standup 5/5/2011: The Most Interesting Standup in the World
  • SF Standup 5/4/2011: Tête-à-tête
Subscribe to Mike's Feed

Author Topics

agile (5)
bundler (2)
jquery (1)
ikea (1)
pairing (1)
amazon cloudfront (1)
internet explorer (1)
paperclip (1)
chef (2)
engineyard (1)
fast_xs (1)
rails (5)
activerecord (1)
rvm (1)
memcache (1)
etags (1)
haproxy (1)
mongrel (1)
selenium (1)
imagemagick (1)
jolt awards (1)
mac (1)
rubymine (1)
jruby (1)
postgres (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >