Uri.fromString throws on some invalid port numbers
See original GitHub issueorg.http4s.Uri.fromString
throws when the port number is greater than 2,147,483,647 (java.lang.Integer.MAX_VALUE
).
Versions Present in 0.20.1 and 0.18.23
$ amm
Loading...
Welcome to the Ammonite Repl 1.1.2
(Scala 2.12.6 Java 1.8.0_181)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $ivy.`org.http4s::http4s-core:0.18.23`
import $ivy.$
@ org.http4s.Uri.fromString("https://example.com:2147483647")
res1: org.http4s.package.ParseResult[org.http4s.Uri] = Right(
Uri(
Some(Scheme(https)),
Some(Authority(None, RegName(example.com), Some(2147483647))),
"",
Query(),
None
)
)
@ // Greater than java.lang.Integer.MAX_VALUE
@ org.http4s.Uri.fromString("https://example.com:2147483648")
java.lang.NumberFormatException: For input string: "2147483648"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:587)
java.lang.Integer.parseInt(Integer.java:615)
scala.collection.immutable.StringLike.toInt(StringLike.scala:301)
scala.collection.immutable.StringLike.toInt$(StringLike.scala:301)
scala.collection.immutable.StringOps.toInt(StringOps.scala:29)
org.http4s.parser.Rfc3986Parser.Port(Rfc3986Parser.scala:85)
org.http4s.parser.Rfc3986Parser.Port$(Rfc3986Parser.scala:83)
org.http4s.parser.RequestUriParser.Port(RequestUriParser.scala:8)
org.http4s.parser.Rfc3986Parser.Authority(Rfc3986Parser.scala:64)
org.http4s.parser.Rfc3986Parser.Authority$(Rfc3986Parser.scala:63)
org.http4s.parser.RequestUriParser.Authority(RequestUriParser.scala:8)
org.http4s.parser.Rfc3986Parser.HierPart(Rfc3986Parser.scala:40)
org.http4s.parser.Rfc3986Parser.HierPart$(Rfc3986Parser.scala:39)
org.http4s.parser.RequestUriParser.HierPart(RequestUriParser.scala:8)
org.http4s.parser.Rfc3986Parser.AbsoluteUri(Rfc3986Parser.scala:25)
org.http4s.parser.Rfc3986Parser.AbsoluteUri$(Rfc3986Parser.scala:24)
org.http4s.parser.RequestUriParser.AbsoluteUri(RequestUriParser.scala:8)
org.http4s.parser.Rfc3986Parser.Uri(Rfc3986Parser.scala:22)
org.http4s.parser.Rfc3986Parser.Uri$(Rfc3986Parser.scala:22)
org.http4s.parser.RequestUriParser.Uri(RequestUriParser.scala:8)
org.http4s.Uri$.$anonfun$fromString$1(Uri.scala:145)
org.http4s.internal.parboiled2.Parser.runRule$1(Parser.scala:143)
org.http4s.internal.parboiled2.Parser.phase0_initialRun$1(Parser.scala:151)
org.http4s.internal.parboiled2.Parser.__run(Parser.scala:204)
org.http4s.Uri$.fromString(Uri.scala:145)
ammonite.$sess.cmd2$.<init>(cmd2.sc:1)
ammonite.$sess.cmd2$.<clinit>(cmd2.sc)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Invalid port specified.' when using an IPv6 URI? - Stack Overflow
To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters. For example, this...
Read more >Addressable::URI::InvalidURIError: Invalid port number: "NAME"
This error happens when you attempt to add an URL using the : . You can always use the latter form.
Read more >URI (Java Platform SE 7 ) - Oracle Help Center
URI. public URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment) throws URISyntaxException.
Read more >Uri class - dart:core library - Dart API
If the URI is not a file URI, calling this throws UnsupportedError. Directory URI. Like Uri.file except that a non-empty URI path ends...
Read more >com.google.common.net.HostAndPort.toString java code examples ...
Returns host and port together as something that can be used as part of a URI. ... it <i>might</i> throw IllegalArgumentException if there...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kevinmeredith I’d expect a
org.http4s.package.ParseResult[org.http4s.Uri]
which is defined astype ParseResult[+A] = Either[ParseFailure, A]
. Throwing is neither aLeft
orRight
😢As far as whether very large port numbers should be a ParseFailure or a URI, I don’t really have an opinion there.
Fixed by #2687.