-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from dispatch/1.1/encode-emoji
[1.1.x] Correctly url encode emoji in path segments
- Loading branch information
Showing
2 changed files
with
29 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
package dispatch.spec | ||
|
||
import org.scalacheck._ | ||
import org.scalacheck.Prop.BooleanOperators | ||
import org.scalacheck.Prop._ | ||
|
||
object UriSpecification extends Properties("Uri") { | ||
/** java.net.URLDecoder should *NOT* be used for testing URI segment decoding | ||
* because it implements completely different functionality: query parameter decoding | ||
*/ | ||
property("encode-decode") = Prop.forAll { (path: String) => | ||
property("Encodes and decodes basic strings") = Prop.forAll { (path: String) => | ||
!path.contains(":") ==> { | ||
new java.net.URI(dispatch.UriEncode.path(path)).getPath == path | ||
} // else Prop.throws(classOf[java.net.URISyntaxException]) | ||
} | ||
|
||
/** if there is nothing to escape, encoder must return original reference */ | ||
property("noop") = Prop.forAll(Gen.choose(0,100)) { (n: Int) => | ||
property("Does nothing if there's nothing eo encode") = Prop.forAll(Gen.choose(0,100)) { (n: Int) => | ||
val path = "A" * n | ||
dispatch.UriEncode.path(path) eq path | ||
} | ||
|
||
property("Encodes emoji correctly") = forAll(Gen.const("unused")) { (sample: String) => | ||
val path = "roma🇮🇹" | ||
new java.net.URI(dispatch.UriEncode.path(path)).getPath == (path) | ||
} | ||
} |