aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-09 16:50:22 +0200
committeradamw <adam@warski.org>2017-07-09 16:50:22 +0200
commit2e8f6d8b221f32e5df7663d296317886a43b1cf0 (patch)
tree82ab4df85c0c7d3416da892f0dd45003ed0c06e6
parent18ed991eefd4ff541e722808f80a48d47df58a57 (diff)
downloadsttp-2e8f6d8b221f32e5df7663d296317886a43b1cf0.tar.gz
sttp-2e8f6d8b221f32e5df7663d296317886a43b1cf0.tar.bz2
sttp-2e8f6d8b221f32e5df7663d296317886a43b1cf0.zip
More tests
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala16
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala3
2 files changed, 13 insertions, 6 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala b/core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala
index b967870..9c42f42 100644
--- a/core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala
@@ -63,7 +63,8 @@ object UriInterpolator {
case class Authority(s: Scheme, v: String = "") extends UriBuilder {
override def parseS(s: String, doEncode: (String) => String): UriBuilder = {
- // authority is terminated by /, ?, # or end of string (there might be other /, ?, # later on e.g. in the query)
+ // authority is terminated by /, ?, # or end of string (there might be
+ // other /, ?, # later on e.g. in the query)
// see https://tools.ietf.org/html/rfc3986#section-3.2
s.split("[/\\?#]", 2) match {
case Array(authorityFragment, rest) =>
@@ -90,11 +91,13 @@ object UriInterpolator {
}
override def build: String = {
- // remove dangling "." which might occur due to optional authority fragments
- val v2 = if (v.startsWith(".")) v.substring(1) else v
- val v3 = if (v.endsWith(".")) v2.substring(0, v2.length - 1) else v2
+ var vv = v
+ // remove dangling "." which might occur due to optional authority
+ // fragments
+ while (vv.startsWith(".")) vv = vv.substring(1)
+ while (vv.endsWith(".")) vv = vv.substring(0, vv.length - 1)
- s.build + v3
+ s.build + vv
}
private def append(x: String, doEncode: String => String): Authority =
@@ -105,7 +108,8 @@ object UriInterpolator {
extends UriBuilder {
override def parseS(s: String, doEncode: (String) => String): UriBuilder = {
- // path is terminated by ?, # or end of string (there might be other ?, # later on e.g. in the query)
+ // path is terminated by ?, # or end of string (there might be other
+ // ?, # later on e.g. in the query)
// see https://tools.ietf.org/html/rfc3986#section-3.3
s.split("[\\?#]", 2) match {
case Array(pathFragments, rest) =>
diff --git a/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala b/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala
index f0eeb1e..4a71163 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/UriInterpolatorTests.scala
@@ -29,7 +29,10 @@ class UriInterpolatorTests extends FunSuite with Matchers {
(uri"http://$v1.com", s"http://$v1.com"),
(uri"http://$v2.com", s"http://$v2hostEncoded.com"),
(uri"http://$None.example.com", s"http://example.com"),
+ (uri"http://$None.$None.example.com", s"http://example.com"),
(uri"http://${Some("sub")}.example.com", s"http://sub.example.com"),
+ (uri"http://${Some("sub1.sub2")}.example.com",
+ s"http://sub1.sub2.example.com"),
(uri"http://${List("sub1", "sub2")}.example.com",
s"http://sub1.sub2.example.com"),
(uri"http://${List("sub", "example", "com")}", s"http://sub.example.com")