Giter VIP home page Giter VIP logo

faraday-follow-redirects's Introduction

Hi there ๐Ÿ‘‹

faraday-follow-redirects's People

Contributors

dependabot[bot] avatar jaredbeck avatar jrochkind avatar olleolleolle avatar semaperepelitsa avatar tisba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

faraday-follow-redirects's Issues

Bug: Unicode Normalization not appropriate for ASCII-8BIT

The Metainspector gem uses Faraday as a dependency and a bug was reported there which seems to be related to this gem.
jaimeiniesta/metainspector#414

Summary:
The redirect response changes the encoding from UTF-8 to ASCII-8BIT

Steps to reproduce:

irb

require 'faraday'
require 'faraday/follow_redirects'
require 'faraday-cookie_jar'

session = Faraday.new(url: 'https://apps.apple.com/us/app/id1501495423') do |faraday|
             faraday.use Faraday::FollowRedirects::Middleware
             faraday.use :cookie_jar
end

session.get

This is the error I got:

/home/ma/.rbenv/versions/3.2.2/lib/ruby/3.2.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/domain_name-0.6.20231109/lib/domain_name.rb:292:in `unicode_normalize'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/domain_name-0.6.20231109/lib/domain_name.rb:292:in `normalize'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/domain_name-0.6.20231109/lib/domain_name.rb:100:in `initialize'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie.rb:553:in `new'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie.rb:553:in `acceptable_from_uri?'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie.rb:592:in `valid_for_uri?'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:82:in `block (3 levels) in each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:76:in `delete_if'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:76:in `block (2 levels) in each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:74:in `each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:74:in `block in each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:73:in `each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar/hash_store.rb:73:in `each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar.rb:163:in `each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar.rb:131:in `each'
	from /home/ma/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/http-cookie-1.0.5/lib/http/cookie_jar.rb:131:in `sort'
	... 14 levels...

From a Rails app, I got the same error, this is the full stack of errors:

[/home/ma/.rbenv/versions/3.2.2/lib/ruby/3.2.0/unicode_normalize/normalize.rb:141:in `normalize'](http://localhost:3000/#)
[domain_name (0.6.20231109) lib/domain_name.rb:292:in `unicode_normalize'](http://localhost:3000/#)
[domain_name (0.6.20231109) lib/domain_name.rb:292:in `normalize'](http://localhost:3000/#)
[domain_name (0.6.20231109) lib/domain_name.rb:100:in `initialize'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie.rb:553:in `new'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie.rb:553:in `acceptable_from_uri?'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie.rb:592:in `valid_for_uri?'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:82:in `block (3 levels) in each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:76:in `delete_if'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:76:in `block (2 levels) in each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:74:in `each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:74:in `block in each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:73:in `each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar/hash_store.rb:73:in `each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar.rb:163:in `each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar.rb:131:in `each'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar.rb:131:in `sort'](http://localhost:3000/#)
[http-cookie (1.0.5) lib/http/cookie_jar.rb:131:in `cookies'](http://localhost:3000/#)
[faraday-cookie_jar (0.0.7) lib/faraday/cookie_jar.rb:12:in `call'](http://localhost:3000/#)
[faraday-follow_redirects (0.3.0) lib/faraday/follow_redirects/middleware.rb:77:in `perform_with_redirection'](http://localhost:3000/#)
[faraday-follow_redirects (0.3.0) lib/faraday/follow_redirects/middleware.rb:85:in `block in perform_with_redirection'](http://localhost:3000/#)
[faraday (2.7.12) lib/faraday/response.rb:42:in `on_complete'](http://localhost:3000/#)
[faraday-follow_redirects (0.3.0) lib/faraday/follow_redirects/middleware.rb:79:in `perform_with_redirection'](http://localhost:3000/#)
[faraday-follow_redirects (0.3.0) lib/faraday/follow_redirects/middleware.rb:65:in `call'](http://localhost:3000/#)
[faraday (2.7.12) lib/faraday/rack_builder.rb:153:in `build_response'](http://localhost:3000/#)
[faraday (2.7.12) lib/faraday/connection.rb:444:in `run_request'](http://localhost:3000/#)
[faraday (2.7.12) lib/faraday/connection.rb:200:in `get'](http://localhost:3000/#)

I could not find exactly the source of the issue, so I don't really have a fully thought-out solution for this but I could fix this issue by changing line 93 of lib/faraday/follow_redirects.rb:

From:
redirect_to_url = safe_escape(response['location'] || '')

To:
redirect_to_url = safe_escape(response['location'].force_encoding("UTF-8") || '')

Same behaviour happens with other urls that will trigger the redirecting behaviour, like for example https://nytimes.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.