Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday affected by rails bug in ActiveSupport::SafeBuffer#gsub with block #93

Closed
radanskoric opened this issue Nov 11, 2011 · 2 comments

Comments

@radanskoric
Copy link
Contributor

This took me a few hours today to locate. I was using koala gem which uses Faraday and I was getting

"NoMethodError: undefined method `bytesize' for nil:NilClass"

The problem was in

lib/faraday/utils.rb:129:in `block in escape'

And it is being caused by

rails/rails#3496

However, if Faraday::Utils#escape is changed from

def escape(s)
  s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) do
    '%' << $1.unpack('H2'*bytesize($1)).join('%').tap { |c| c.upcase! }
  end
end

to

def escape(s)   
  s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) do |match|
    '%' << match.unpack('H2'*bytesize(match)).join('%').tap { |c| c.upcase! }
  end
end

everything works.

Is there any particular reason why $1 is used instead of the block parameter?

@technoweenie
Copy link
Member

Not sure. If $1 isn't used, you can probably remove the parens around the regex too. Feel free to send in a pull request with your changes.

@radanskoric
Copy link
Contributor Author

Pull request sent: #94

jgarber added a commit to jgarber/faraday that referenced this issue Jun 24, 2013
jgarber added a commit to jgarber/faraday that referenced this issue Jun 24, 2013
jgarber added a commit to jgarber/faraday that referenced this issue Jun 24, 2013
mislav added a commit that referenced this issue Jun 25, 2013
mislav added a commit that referenced this issue Jun 25, 2013
Fix ActiveSupport::SafeBuffer#gsub bug again

Fixes #93, closes #260
mislav added a commit that referenced this issue Jun 25, 2013
ismith added a commit to ismith/faraday that referenced this issue Sep 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants