-
Notifications
You must be signed in to change notification settings - Fork 43
Allow Faraday 2.x #91
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
Conversation
…raday_follow-redirects gem The new gem is compatible with both faraday 1 and 2, while faraday-middleware (which included a redirect middleware) has a gemspec that does not allow faraday 2.
…encoding On upgrade to faraday 2, HTTP responses can come back in specific encodings per the content-type of response. This effected one of our tests, that is using a live query to google.com (probably not a great idea), that comes back ISO-8859-1. But it actually would have failed if UTF-8 too, because we're trying to gsub some intentionally illegal bytes. I am not sure if the approach to encoding is totally sound in this gem in general -- XML does have to be Unicode legally, but can be UTF-8 or -16, this strip routine may be assuming UTF8? But not actually properly making it with the ruby UTF8 encoding? But this is just an attempt to change as little as possible leaving as backward compat as possible while passing tests in faraday 2; and resolving the specific problem of the strip_invalid_utf_8_chars failing when response comes back with ruby encoding tag from faraday 2.
@mcritchlow and @orangewolf anyone interested in reviewing? If I don't hear from anyone, I may do a merge myself. |
lib/oai/client.rb
Outdated
@@ -330,14 +331,27 @@ def parse_date(value) | |||
# Regex is from WebCollab: | |||
# http://webcollab.sourceforge.net/unicode.html | |||
def strip_invalid_utf_8_chars(xml) | |||
xml && xml.gsub(/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F] | |||
return xml unless xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return xml if xml
? this seems like it only ever returns nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, it exits the method early to return nil unless xml
is present. Similar to what the xml &&
did in the one-liner version previously. Do you think it would read better return nil unless xml
? Or other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that reads more intentional and direct to me, but its a small quibble as long as this is doing what is intended.
Thanks @orangewolf! |
Closes #89
Allow Faraday 2.x, by switching from faraday-middleware to the new faraday_follow-redirects gem
By switching from faraday-middleware to the new faraday_follow-redirects gem
The new gem is compatible with both faraday 1 and 2, while faraday-middleware (which included a redirect middleware) has a gemspec that does not allow faraday 2.
I manually tested on faraday 1 by editing Gemfile locally -- it passes. I'm not sure if we want to regularly/automated test on both faraday 1 and 2? Right now we have no automated CI at all, see #87
Strip invalid chars without raising encoding exception regardless of encoding
On upgrade to faraday 2, HTTP responses can come back in specific encodings per the content-type of response. This effected one of our tests, that is using a live query to google.com (probably not a great idea), that comes back ISO-8859-1. But it actually would have failed if UTF-8 too, because we're trying to gsub some intentionally illegal bytes. I am not sure if the approach to encoding is totally sound in this gem in general -- XML does have to be Unicode legally, but can be UTF-8 or -16, this strip routine may be assuming UTF8? But not actually properly making it with the ruby UTF8 encoding?
But this is just an attempt to change as little as possible leaving as backward compat as possible while passing tests in faraday 2; and resolving the specific problem of the strip_invalid_utf_8_chars failing when response comes back with ruby encoding tag from faraday 2.