Backport of regexp fixes and SHA improvements to 0.8.x

I've backported 00bb02978e33417d72ddf573a61ee7c10b35d9aa and 9f5a83a6b2861c256861375e81859d5cbfdfca70 to address security issue OSVDB-110439.

Should e88afeceb036fe4d44f7c7787c7e988e1350c2dc also be backported, or is this PR sufficient?

Also, I pinned capybara to a version that supports Ruby 1.9.2.