Skip to content

Commit

Permalink
Properly parsing single-segment paths as relative uris
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jan 26, 2021
1 parent 999ac2b commit 550d2fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/src/main/scala/sttp/model/UriInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ object UriInterpolator {

override def tokenize(s: String): (Tokenizer, Vector[Token]) = {
SchemePattern.findPrefixOf(s) match {
case Some(scheme) if scheme.length == s.length =>
(this, Vector(StringToken(scheme))) // scheme (or another component) might be continued
case _ if s.isEmpty => (this, Vector(StringToken(""))) // scheme (or another component) might be continued
// #59: if the entire string matches the pattern, then there's no scheme terminator (`:`). This means there's
// no scheme, hence - tokenizing as a relative uri.
case Some(scheme) if scheme.length == s.length => AfterScheme.tokenize(scheme)
case _ if s.isEmpty => (this, Vector(StringToken(""))) // scheme (or another component) might be continued
case Some(scheme) if s(scheme.length) == ':' =>
val rest = s.substring(scheme.length + 1)
val (next, afterSchemeTokens) = AfterScheme.tokenize(rest)
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/scala/sttp/model/UriInterpolatorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class UriInterpolatorTests extends AnyFunSuite with Matchers {
(uri"/a/b/c?x=$None", "/a/b/c"),
(uri"/$v1/b/c", s"/$v1/b/c"),
(uri"/$v1/$v2/c", s"/$v1/$v2encoded/c"),
(uri"a", "a"),
(uri"$v1", s"$v1"),
(uri"a/b/c", "a/b/c"),
(uri"$v1/b/c", s"$v1/b/c"),
(uri"$v1/$v2/c", s"$v1/$v2encoded/c"),
Expand Down

0 comments on commit 550d2fa

Please sign in to comment.