Merge pull request #21384 from jrudolph/wip-21281-fix-authorization-param-rendering

=htc #21281 render empty params double quoted in headers like `Authorization`
This commit is contained in:
Johannes Rudolph 2016-09-07 19:20:57 +02:00 committed by GitHub
commit fc3761bc4b
3 changed files with 7 additions and 3 deletions

View file

@ -185,10 +185,10 @@ private[http] trait Rendering {
/**
* Renders the given string either directly (if it only contains token chars)
* or in double quotes (if it contains at least one non-token char).
* or in double quotes (if it is empty or contains at least one non-token char).
*/
def ~~#(s: String): this.type =
if (CharacterClasses.tchar matchesAll s) this ~~ s else ~~#!(s)
if (s.nonEmpty && CharacterClasses.tchar.matchesAll(s)) this ~~ s else ~~#!(s)
/**
* Renders the given string in double quotes.

View file

@ -140,6 +140,8 @@ class HttpHeaderSpec extends FreeSpec with Matchers {
"""Fancy yes="n:o",nonce=42""")
"""Authorization: Fancy yes=no,nonce="4\\2"""" =!=
Authorization(GenericHttpCredentials("Fancy", Map("yes" "no", "nonce" """4\2""")))
"""Authorization: Other yes=no,empty=""""" =!=
Authorization(GenericHttpCredentials("Other", Map("yes" "no", "empty" "")))
"Authorization: Basic Qm9iOg==" =!=
Authorization(BasicHttpCredentials("Bob", ""))
"""Authorization: Digest name=Bob""" =!=
@ -182,6 +184,8 @@ class HttpHeaderSpec extends FreeSpec with Matchers {
"Content-Disposition: form-data" =!= `Content-Disposition`(ContentDispositionTypes.`form-data`)
"Content-Disposition: attachment; name=field1; filename=\"file/txt\"" =!=
`Content-Disposition`(ContentDispositionTypes.attachment, Map("name" "field1", "filename" "file/txt"))
"Content-Disposition: attachment; name=field1; other=\"\"" =!=
`Content-Disposition`(ContentDispositionTypes.attachment, Map("name" "field1", "other" ""))
}
"Content-Encoding" in {

View file

@ -29,7 +29,7 @@ class RenderingSpec extends WordSpec with Matchers {
}
"correctly render escaped Strings" in {
(new StringRendering ~~# "").get shouldEqual ""
(new StringRendering ~~# "").get shouldEqual "\"\""
(new StringRendering ~~# "hello").get shouldEqual "hello"
(new StringRendering ~~# """hel"lo""").get shouldEqual """"hel\"lo""""
}