-
Notifications
You must be signed in to change notification settings - Fork 787
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
Address Uri#fromString Defect for Parsing the Port #2687
Changes from 4 commits
ad2f1da
f425ad3
6e9f135
283cae5
66252fa
e997a9e
8664ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,12 @@ class UriSpec extends Http4sSpec with MustThrownMatchers { | |
} | ||
|
||
"parse port correctly" >> { | ||
"if there is one" in { | ||
val uri = getUri("http://localhost:8080/") | ||
uri.port must_=== Some(8080) | ||
} | ||
"if there is a valid (non-negative) one" >> prop { nonNegative: Int => | ||
{ | ||
val uri = getUri(s"http://localhost:$nonNegative/") | ||
uri.port must_=== Some(nonNegative) | ||
} | ||
}.setGen(Gen.choose[Int](0, Int.MaxValue)) | ||
"if there is none" in { | ||
val uri = getUri("http://localhost/") | ||
uri.port must_=== None | ||
|
@@ -84,6 +86,44 @@ http://example.org/a file | |
} | ||
} | ||
|
||
"fail to parse port" >> { | ||
"if it's negative" >> prop { negative: Int => | ||
{ | ||
val uri: ParseResult[Uri] = Uri.fromString(s"http://localhost:$negative/") | ||
uri match { | ||
case Left(ParseFailure("Invalid URI", _)) => ok | ||
case unexpected => ko(unexpected.toString) | ||
} | ||
} | ||
}.setGen(Gen.choose[Int](Int.MinValue, -1)) | ||
"if it's larger than Int.MaxValue" >> prop { tooBig: Long => | ||
{ | ||
val uri: ParseResult[Uri] = Uri.fromString(s"http://localhost:$tooBig/") | ||
uri match { | ||
case Left(ParseFailure("Invalid URI", _)) => ok | ||
case unexpected => ko(unexpected.toString) | ||
} | ||
} | ||
}.setGen(Gen.choose[Long]((Int.MaxValue: Long) + 1, Long.MaxValue)) | ||
"if it's not a number or an empty String" >> prop { notNumber: String => | ||
{ | ||
val uri: ParseResult[Uri] = Uri.fromString(s"http://localhost:$notNumber/") | ||
uri match { | ||
case Left(ParseFailure("Invalid URI", _)) => ok | ||
case unexpected => ko(unexpected.toString) | ||
} | ||
} | ||
}.setGen(Gen.alphaNumStr.suchThat(str => | ||
str.nonEmpty && Either.catchOnly[NumberFormatException](str.toInt).isLeft)) | ||
"for an empty String" in { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referencing #2664 (comment), locallyy, this test failed:
Per https://tools.ietf.org/html/rfc3986#page-22,
Per https://tools.ietf.org/html/rfc3986#page-22,
this test, it seems clear to me, should fail, not pass. In other words, I should replace this "should fail" test with a "should parse to port 80" one. Please let me know if you disagree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, That seems correct via the spec. |
||
val uri: ParseResult[Uri] = Uri.fromString("http://localhost:/") | ||
uri match { | ||
case Left(ParseFailure("Invalid URI", _)) => ok | ||
case unexpected => ko(unexpected.toString) | ||
} | ||
} | ||
} | ||
|
||
"support a '/' operator when original uri has trailing slash" in { | ||
val uri = getUri("http://localhost:8080/") | ||
val newUri = uri / "echo" | ||
|
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.
I was able to use your suggestion, #2664 (comment), @SystemFw. Thanks for it!