A simple defensive library to encode/decode URL components. https://github.com/ethauvin/urlencoder
Find a file
2022-12-31 01:37:51 -08:00
.github/workflows Added GitHub workflow 2022-12-30 20:14:28 -08:00
.idea Initial commit. 2022-12-30 17:45:42 -08:00
gradle/wrapper Initial commit. 2022-12-30 17:45:42 -08:00
lib Changed the allow parameter to also take a string 2022-12-31 01:37:51 -08:00
.gitattributes Initial commit. 2022-12-30 17:45:42 -08:00
.gitignore Initial commit. 2022-12-30 17:45:42 -08:00
gradlew Initial commit. 2022-12-30 17:45:42 -08:00
gradlew.bat Initial commit. 2022-12-30 17:45:42 -08:00
LICENSE.txt Initial commit. 2022-12-30 17:45:42 -08:00
README.md Added link to Java version 2022-12-30 22:42:18 -08:00
settings.gradle.kts Initial commit. 2022-12-30 17:45:42 -08:00

License Nexus Snapshot

Quality Gate Status GitHub CI

URL Encoder for Kotlin and Java

A simple library to encode/decode URL parameters.

This library was adapted from the RIFE2 Web Application Framework.
A pure Java version can also be found at https://github.com/gbevin/urlencoder.

For decades we've been using java.net.URLEncoder because of its improper naming. It is actually intended to encode HTML form parameters, not URLs.

Android's Uri.encode also addresses this issue.

Examples (TL;DR)

UrlEncoder.encode("%#okékÉȢ smile!😁") // -> %25%23ok%C3%A9k%C3%89%C8%A2%20smile%21%F0%9F%98%81
UrlEncoder.encode("?test=a test", '=', '?') // -> ?test=a%20test

UrlEncoder.decode("%25%23ok%C3%A9k%C3%89%C8%A2%20smile%21%F0%9F%98%81") // -> %#okékÉȢ smile!😁

Gradle, Maven, etc.

To use with Gradle, include the following dependency in your build file:

repositories {
    mavenCentral()
    maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}

dependencies {
    implementation("net.thauvin.erik:urlencoder:0.9-SNAPSHOT")
}

Instructions for using with Maven, Ivy, etc. can be found on Maven Central.