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

Fix UserInfo with plus sign (#2713) #2727

Merged
merged 3 commits into from Jul 19, 2019
Merged

Conversation

@valydia
Copy link
Contributor

@valydia valydia commented Jul 16, 2019

No description provided.

Copy link
Member

@rossabaker rossabaker left a comment

Thanks, @valydia! Good find on the + being what triggers this. However, + is a valid character there, and does not mean space in this context. I think the problem is not with the encoding, but the decoding. The decode in the parser delegates to URLDecoder.decode, which is designed for the similar-but-not-the-same application/x-www-form-urlencoded. That's not something we should use in a URI outside the query string. I think replacing the decode call with UrlCoding.urlDecode might fix the bug, and let us continue to treat + as the other subdelims.

Loading


"skip encoding subdelims except '+' in password" in {
renderString(UserInfo("hi", Some("!$&'()*+,;="))) must_== "hi:!$&'()*%2B,;="
}
Copy link
Member

@rossabaker rossabaker Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests will break, but maybe it's good to explicitly test that all the subdelims aren't encoded.

Loading

val userInfo = UserInfo("username+", Some("password+"))
HttpCodec[UserInfo].parse(renderString(userInfo)) must_== Right(userInfo)
}
}
Copy link
Member

@rossabaker rossabaker Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely keep this test.

Loading

@valydia
Copy link
Contributor Author

@valydia valydia commented Jul 16, 2019

@rossabaker Thanks for the guidance, I wasn't entirely sure which way to fix it...

Loading

Copy link
Member

@rossabaker rossabaker left a comment

👍 if green, but I'm not sure: see below.

Loading

@@ -144,6 +144,6 @@ private[http4s] trait Rfc3986Parser

def SubDelims = rule { "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "=" }

protected def decode(s: String) = URLDecoder.decode(s, charset.name)
protected def decode(s: String) = UrlCodingUtils.urlDecode(s, charset)
Copy link
Member

@rossabaker rossabaker Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this might break tests in the query string, which do encode +. I was thinking of replacing the decode calls in UserInfo.Parser. But if it works, 👍, because this is correct in more cases.

Loading

Copy link
Contributor Author

@valydia valydia Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, I think I should correct this, even if the ci passes, because I am not sure that explicit test cases for '+' exist ...

Loading

Copy link
Member

@rossabaker rossabaker Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the query is not using that function. It's path and regname.

Loading

Copy link
Member

@rossabaker rossabaker left a comment

Looks like my query string fear was unfounded. 👍

Loading

@rossabaker rossabaker added the bug label Jul 17, 2019
@rossabaker rossabaker merged commit 5909d2b into http4s:master Jul 19, 2019
1 check passed
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants