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

Content-type incorrectly parsed by play.api.test.ResultExtractors #4719

Closed
Oduig opened this issue Jun 19, 2015 · 2 comments
Closed

Content-type incorrectly parsed by play.api.test.ResultExtractors #4719

Oduig opened this issue Jun 19, 2015 · 2 comments
Milestone

Comments

@Oduig
Copy link

Oduig commented Jun 19, 2015

Referring to this line: https://github.com/playframework/playframework/blob/2.3.x/framework/src/play-test/src/main/scala/play/api/test/Helpers.scala#L340

I was using the content type "text/html;charset=utf-8". The string matches the requirement on line 340 but then fails to parse because there is no space after the semicolon. Rather than a Some("utf-8") or a None, the function returns a Some(""). This causes an error somewhere down the line which is quite difficult to trace.

The spec for content-type/charset does not require a space after the semicolon. I would suggest something like the following:

header(CONTENT_TYPE, of) match {
    case Some(s) => 
        val parts = s.split(";\\s*charset=")
        if (parts.size > 1) Some(parts.drop(1).mkString.trim) else None
    case _ => None
}
@marcospereira
Copy link
Member

Thanks @Oduig! Do you mind submitting a pull requests that fixes this problem? If it comes with some tests/specs it will be even better.

Oduig pushed a commit to Oduig/playframework that referenced this issue Jun 20, 2015
Oduig pushed a commit to Oduig/playframework that referenced this issue Jun 22, 2015
jroper added a commit that referenced this issue Jun 22, 2015
Fixes #4719 - Content-type incorrectly parsed by play.api.test.ResultExtractors
@marcospereira
Copy link
Member

Fixed by #4723.

ClaraAllende pushed a commit to ClaraAllende/playframework that referenced this issue Jul 14, 2015
@jroper jroper added this to the 2.3.10 milestone Aug 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants