Skip to content

Commit

Permalink
fix parse broken when header value is null (#575) (#581)
Browse files Browse the repository at this point in the history
* fix parse broken when header value is null

* fix style

* revert not need change

* improve match case

* revert HttpHeader and update  HeaderParser.failure

* update assert

---------

Co-authored-by: Laglangyue <[email protected]>
Co-authored-by: tangjiafu <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent d551c1e commit eb43f55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ private[http] class HeaderParser(
def failure(error: Throwable): HeaderParser.Failure =
HeaderParser.Failure {
error match {
case IllegalUriException(info) => info
case NonFatal(e) => ErrorInfo.fromCompoundString(e.getMessage)
case IllegalUriException(info) => info
case NonFatal(e) if e.getMessage == null => ErrorInfo.fromCompoundString(e.toString)
case NonFatal(e) => ErrorInfo.fromCompoundString(e.getMessage)
}
}
def ruleNotFound(ruleName: String): Result = HeaderParser.RuleNotFound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,13 @@ class HttpHeaderSpec extends AnyFreeSpec with Matchers {
parse("User-Agent", "(" * 10000).errors.head shouldEqual
ErrorInfo("Illegal HTTP header 'User-Agent': Illegal header value", "Header comment nested too deeply")
}

"should not broken when header-value is null" in {
val errors = parse("Content-Disposition", null).errors
errors should have size 1
errors.head shouldBe an[ErrorInfo]
}

}

implicit class TestLine(line: String) {
Expand Down

0 comments on commit eb43f55

Please sign in to comment.