Skip to content

Commit 113a708

Browse files
committed
fixed empty path param handling
1 parent 8df812f commit 113a708

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

commons-core/src/main/scala/com/avsystem/commons/rest/data.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ sealed trait RestValue extends Any {
2121
case class PathValue(value: String) extends AnyVal with RestValue
2222
object PathValue {
2323
def splitDecode(path: String): List[PathValue] =
24-
path.split("/").iterator.filter(_.nonEmpty).map(s => PathValue(UrlEncoding.decode(s))).toList
24+
path.split("/").iterator.map(s => PathValue(UrlEncoding.decode(s))).toList match {
25+
case PathValue("") :: tail => tail
26+
case res => res
27+
}
28+
2529
def encodeJoin(path: List[PathValue]): String =
2630
path.iterator.map(pv => UrlEncoding.encode(pv.value)).mkString("/", "/", "")
2731
}
@@ -46,7 +50,7 @@ object QueryValue {
4650

4751
def decode(queryString: String): Mapping[QueryValue] = {
4852
val builder = Mapping.newBuilder[QueryValue]
49-
queryString.split(FormKVPairSep).iterator.map(_.split(FormKVSep, 2)).foreach {
53+
queryString.split(FormKVPairSep).iterator.filter(_.nonEmpty).map(_.split(FormKVSep, 2)).foreach {
5054
case Array(name, value) => builder += UrlEncoding.decode(name) -> QueryValue(UrlEncoding.decode(value))
5155
case _ => throw new IllegalArgumentException(s"invalid query string $queryString")
5256
}

commons-core/src/test/scala/com/avsystem/commons/rest/AbstractRestCallTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ abstract class AbstractRestCallTest extends FunSuite with ScalaFutures {
4747
}
4848

4949
test("prefixed GET") {
50-
testCall(_.prefix("p0", "h0", "q0").subget(0, 1, 2))
50+
testCall(_.prefix("", "h0", "q0").subget(0, 1, 2))
5151
}
5252

5353
test("custom response with headers") {

0 commit comments

Comments
 (0)