Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dave - fixed bug with encoding of path parameter values into URLs
- Loading branch information
1 parent
ca4a388
commit 9cdb49b
Showing
6 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/scala/io/fintrospect/util/PathSegmentEncoderDecoder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.fintrospect.util | ||
|
||
import java.net.URI | ||
|
||
object PathSegmentEncoderDecoder { | ||
def encode(in: String): String = { | ||
in.split("/").map(new URI("http", "localhost", _).getRawFragment).mkString("%2F") | ||
} | ||
|
||
def decode(in: String): String = new URI("http://localhost/" + in).getPath.substring(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/scala/io/fintrospect/util/PathSegmentEncoderDecoder$Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.fintrospect.util | ||
|
||
import io.fintrospect.util.PathSegmentEncoderDecoder._ | ||
import org.scalatest.{FunSpec, ShouldMatchers} | ||
|
||
class PathSegmentEncoderDecoder$Test extends FunSpec with ShouldMatchers{ | ||
|
||
describe("encode/decode") { | ||
it("roundtrips") { | ||
val inputString = " :@-._~!$&'()*+,;=" | ||
decode(encode(inputString)) shouldBe inputString | ||
} | ||
|
||
it("does not url encode reserved characters") { | ||
encode(":@-._~!$&'()*+,;=") shouldEqual ":@-._~!$&'()*+,;=" | ||
} | ||
|
||
it("handles spaces and forward slashes gracefully") { | ||
encode("a path/+piece") shouldEqual "a%20path%2F+piece" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters