lemonlabsuk / scala-uri

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

GIT urls should be treated specifically #106

Closed pshirshov closed 4 years ago

pshirshov commented 4 years ago

Thanks for a nice library. Unfortunately it cannot handle GIT URIs, could you fix that please?

@ Uri.parse("git+ssh://git@github.com:org/project.git")
io.lemonlabs.uri.parsing.UriParsingException: Invalid URL could not be parsed. Invalid input 'o', expected _int (line 1, column 26):
git+ssh://git@github.com:org/project.git
                         ^
  io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:231)
  io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:228)
  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:38)
  scala.util.Failure.recoverWith(Try.scala:236)
  io.lemonlabs.uri.parsing.UrlParser.mapParseError(UrlParser.scala:228)
  io.lemonlabs.uri.parsing.UrlParser.parseUrl(UrlParser.scala:271)
  io.lemonlabs.uri.parsing.UrlParser$.parseUrl(UrlParser.scala:322)
  io.lemonlabs.uri.parsing.UriParser$.$anonfun$parseUri$1(UriParser.scala:27)
  scala.util.Failure.orElse(Try.scala:224)
  io.lemonlabs.uri.parsing.UriParser$.parseUri(UriParser.scala:27)
  io.lemonlabs.uri.Uri$.$anonfun$parseTry$2(Uri.scala:81)
  scala.util.Success.flatMap(Try.scala:251)
  io.lemonlabs.uri.Uri$.parseTry(Uri.scala:81)
  io.lemonlabs.uri.Uri$.parse(Uri.scala:87)
  ammonite.$sess.cmd9$.<init>(cmd9.sc:1)
  ammonite.$sess.cmd9$.<clinit>(cmd9.sc)

@ Url.parse("git+ssh://git@github.com:org/project.git")
io.lemonlabs.uri.parsing.UriParsingException: Invalid URL could not be parsed. Invalid input 'o', expected _int (line 1, column 26):
git+ssh://git@github.com:org/project.git
                         ^
  io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:231)
  io.lemonlabs.uri.parsing.UrlParser$$anonfun$mapParseError$1.applyOrElse(UrlParser.scala:228)
  scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:38)
  scala.util.Failure.recoverWith(Try.scala:236)
  io.lemonlabs.uri.parsing.UrlParser.mapParseError(UrlParser.scala:228)
  io.lemonlabs.uri.parsing.UrlParser.parseUrl(UrlParser.scala:271)
  io.lemonlabs.uri.parsing.UrlParser$.parseUrl(UrlParser.scala:322)
  io.lemonlabs.uri.Url$.parseTry(Uri.scala:560)
  io.lemonlabs.uri.Url$.parse(Uri.scala:554)
  ammonite.$sess.cmd10$.<init>(cmd10.sc:1)
  ammonite.$sess.cmd10$.<clinit>(cmd10.sc)

@ Url.parse("git@github.com:org/project.git")
res11: Url = RelativeUrl(RootlessPath(Vector("git@github.com:org", "project.git")), QueryString(Vector()), None)
theon commented 4 years ago

Thanks for raising this.

From the git-clone man page:

The following syntaxes may be used with them:

  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/
  • ftp[s]://host.xz[:port]/path/to/repo.git/

An alternative scp-like syntax may also be used with the ssh protocol:

  • [user@]host.xz:path/to/repo.git/

The 'scp-like syntax' is the troublesome one. It uses a : to separate the host from the path, which seems to be something neither RFC-3986 nor WHATWG supports.

I feel the best option would be to add a new parser and new methods:

If it's an option, you can currently workaround the issue by using SSH urls in the format ssh://git@github.com/org/project.git. I just tried it and it seems to work

Related:

theon commented 4 years ago

@pshirshov This is now released in version 2.1.0. See support in the docs. Let me know if you need anything else. Thanks again.