question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uri.fromString throws on some invalid port numbers

See original GitHub issue

org.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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
niijcommented, May 24, 2019

@kevinmeredith I’d expect a org.http4s.package.ParseResult[org.http4s.Uri] which is defined as type ParseResult[+A] = Either[ParseFailure, A]. Throwing is neither a Left or Right 😢

As far as whether very large port numbers should be a ParseFailure or a URI, I don’t really have an opinion there.

0reactions
rossabakercommented, Jul 5, 2019

Fixed by #2687.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found