mirror of
https://github.com/gbevin/urlencoder.git
synced 2025-04-28 16:38:12 -07:00
Compare commits
3 commits
2409932ac5
...
783a044cab
Author | SHA1 | Date | |
---|---|---|---|
783a044cab | |||
70bfd2e663 | |||
7e03e1e275 |
2 changed files with 34 additions and 2 deletions
34
README.md
34
README.md
|
@ -47,7 +47,7 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
|
|||
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation("com.uwyn:urlencoder:1.1.0")
|
||||
implementation("com.uwyn:urlencoder:1.2.0")
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -94,3 +94,35 @@ java -jar lib/build/libs/urlencoder-*.jar "%#okékÉȢ" # -> %25%23ok%C
|
|||
|
||||
java -jar lib/build/libs/urlencoder-*.jar -d "a%20test%20%26" # -> a test &
|
||||
```
|
||||
|
||||
## Why not simply use `java.net.URLEncoder`?
|
||||
|
||||
Apart for being quite inefficient, some URL components encoded with `URLEncoder.encode` might not be able to be properly decoded.
|
||||
|
||||
For example, a simply search query such as:
|
||||
|
||||
```kotlin
|
||||
var u = URLEncoder.encode("foo + bar", StandardCharsets.UTF_8);
|
||||
```
|
||||
|
||||
would be encoded as:
|
||||
|
||||
```
|
||||
foo+%28+bar
|
||||
```
|
||||
|
||||
Trying to decode it with [Spring](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/UriUtils.html#decode(java.lang.String,java.lang.String)), for example:
|
||||
|
||||
```kotlin
|
||||
UriUtils.decode(u, StandardCharsets.UTF_8));
|
||||
```
|
||||
|
||||
would return:
|
||||
|
||||
```
|
||||
foo+++bar
|
||||
```
|
||||
|
||||
Unfortunately, decoding with [Uri.decode](https://developer.android.com/reference/android/net/Uri#decode(java.lang.String)) on Android, [decodeURI](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI) in Javascript, etc. would yield the exact same result.
|
||||
|
||||

|
||||
|
|
|
@ -13,7 +13,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "com.uwyn"
|
||||
version = "1.2.0"
|
||||
version = "1.2.1-SNAPSHOT"
|
||||
|
||||
val mavenName = "UrlEncoder"
|
||||
val javaMainClass = "$group.${rootProject.name}.$mavenName"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue