lemonlabsuk / scala-uri

Simple scala library for building and parsing URIs
Other
305 stars 34 forks source link

Inconsistent URL and Host parsing #204

Closed a-shkarupin closed 4 years ago

a-shkarupin commented 4 years ago

Hosts that begin with an IP but have further leading characters are not parsed correctly. It's possible to create a Url object, get it's host and fail to parse it using the Host.parse method. See example below.

To Reproduce

import io.lemonlabs.uri.Host
import io.lemonlabs.uri.Url

val url = Url.parse("http://1.2.3.4.blah/")
Host.parse(url.hostOption.get.toString)

io.lemonlabs.uri.parsing.UriParsingException: Invalid Host could not be parsed. Invalid input '.', expected Digit or 'EOI' (line 1, column 8):
1.2.3.4.blah
       ^
  at io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:231)
  at io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:228)
  at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
  at scala.util.Failure.recoverWith(Try.scala:203)
  at io.lemonlabs.uri.parsing.UrlParser.mapParseError(UrlParser.scala:228)
  at io.lemonlabs.uri.parsing.UrlParser.parseHost(UrlParser.scala:244)
  at io.lemonlabs.uri.parsing.UrlParser$.parseHost(UrlParser.scala:295)
  at io.lemonlabs.uri.Host$.parseTry(Host.scala:74)
  at io.lemonlabs.uri.Host$.parse(Host.scala:80)
  ... 40 elided
theon commented 4 years ago

Many thanks for raising this!

This has now been fixed and released in version 2.3.1. Let me know if you have any further issues