-
-
Notifications
You must be signed in to change notification settings - Fork 621
Fix for OAuth2::Error trying to encode non-encodable objects #380
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
A start at attempting to provide coverage of the non-StandardError behavior that this class implements. Also, no longer rely on a local being defined inside of an `if`.
If the response body is an object that does not respond to `encode`, don't try to encode it. Add spec coverage for a UTF-8 character being returned in a response. Additionally, make `error_message` into a private method, since no other file calls it.
Not sure under what circumstances an object would respond to `encoding` and not `encode` but better safe than sorry.
The :invalid and :undef options to `encode` are definitely necessary, and nothing was really testing them.
Seems like RSpec matchers can blow up with garbage characters under some circumstances
|
Oh now this is interesting. The Travis builds in Ruby 1.9 and 2.0 are failing . . . . I believe that this behavior may have been broken in Ruby versions < 2.1 for some time but there was just no test to fail for it? Apparently the behavior of 2.0.0-p648 :001 > "\xAD bad!".encode("UTF-8", :invalid => :replace)
=> "\xAD bad!"2.3.3-p222 :001 > "\xAD bad!".encode("UTF-8", :invalid => :replace)
=> "� bad!" The JRuby builds are also failing in the same way as well. |
|
@jhmoore This is something I would vote for using rspec-pending_for to skip those specs on Ruby < 2.1. Then we can remove the caveat when we drop old Rubies in the following major release, 3.0. Something like this (untested, and not sure if the version strings for JRuby use MRI version numbers, but I think they do). |
It seems like this has always been broken, but no spec was ever passing in an invalid byte sequence as a response message. The behavior of `encode` changed in 2.1, and support for these older rubies is about to be dropped anyways.
|
Hmm, looks like the JRuby versions are still running with MRI version numbers passed in. Also haha 1.9.3 seems unable to even parse the file at all: |
Also try to skip invalid character encoding spec in all JRuby
Turns out String#lines returns an enumerator in 1.9.3 and an array in most everything else.
|
@pboling looks like that did the trick! |
pboling
left a comment
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.
Awesome.
|
@pboling thanks! Is the list in this milestone an accurate list of blockers? (Other than #261 which can be closed out) |
|
@jhmoore AFAIK, yes. There may be other things lurking in issues, but I expect if we can clear those we'll be good to release. |
|
Ok cool, thanks. I'll see what I can pick off there. |
We are pretty interested in seeing
2.0.0released so we can unfork ourselves -- I was looking down the list of remaining items in https://github.com/oauth-xx/oauth2/milestone/1 and thought I might try to pitch in.This is a replacement for #261 which looks dead. The issue is trying to call
encodeon something which does not have anencodemethod. However in trying to test (drive!) a fix for it, it seemed like there were no tests present at all for theOAuth2::Errorclass. I created a new spec file and did my best to backfill specs for the already-existing functionality (of which there is quite a bit tacked on to the inheritedStandardErrorbehavior).The GitHub diff of the error class itself looks kind of weird because of indentation, but a brief rundown of changes:
#error_messageprivate. Nothing outside this file talks to this method, and it sure seems like a "generate a formatted string for the error message" internal thing.error_messageinside ofdef error_message,messageinside a class descending fromStandardError).#initializenot rely on a local being defined only inside anifbranch. (Haha I know it works because Ruby is maaaagic, but y'know)error_descriptionis present but noterror, avoid displaying an errant": ".Also: I was unable to determine why
@codeand@descriptionare set and made intoattr_readers -- nothing outside the file seems to talk to those things either. However, folks using this error in their implementations certainly could be relying on being able to callerror.codeor whatever. I elected to leave them there (and test that they are there), but open to suggestions on that front.