Amazon S3 Gem Invalid Multibyte Escape

26 May 2013

After cloning an old project from Github onto a new computer, I started the local server only to receive this error:

../rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require': /Users/jasondemeuse/.rvm/gems/ruby-2.0.0-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:84: invalid multibyte escape: /[\x80-\xFF]/ (SyntaxError)

I didn't understand why there would be a RegEx error, since I hadn't made any edits, especially to the extensions.rb file. After searching for awhile, I found some answers that indicated that changing

[\x80-\xFF]

to

'[\x80-\xFF]', nil, 'n'

but I didn't want to patch third party gems myself.

Turns out, there is a much simpler fix for this specific issue in Amazon S3. Adding the following line to the same `extensions.rb` file will get rid of the error without having to make any other changes*. Be sure to add the line even before the #:stopdoc:

# encoding: BINARY

After that starting the local rails server worked without issue.

*If there is a better way to fix this, I would appreciate you letting me know so I can edit this!

Amazon S3: Invalid Multibyte Escape