Removed main arguments splitting
This commit is contained in:
parent
fad3714ae0
commit
a4b2c975e1
3 changed files with 11 additions and 12 deletions
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
|
@ -53,7 +53,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
run: ./gradlew sonarqube
|
run: ./gradlew sonar
|
||||||
|
|
||||||
- name: Cleanup Gradle Cache
|
- name: Cleanup Gradle Cache
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -31,10 +31,10 @@ import kotlin.system.exitProcess
|
||||||
*/
|
*/
|
||||||
object UrlEncoder {
|
object UrlEncoder {
|
||||||
private val hexDigits = "0123456789ABCDEF".toCharArray()
|
private val hexDigits = "0123456789ABCDEF".toCharArray()
|
||||||
internal val usage = """Usage : kotlin -cp urlencoder-*.jar ${UrlEncoder::class.java.name} [-ed] text
|
internal val usage =
|
||||||
Encode and decode URL parameters.
|
"Usage : kotlin -cp urlencoder-*.jar ${UrlEncoder::class.java.name} [-ed] text" + System.lineSeparator() +
|
||||||
-e encode (default)
|
"Encode and decode URL parameters." + System.lineSeparator() + " -e encode (default) " +
|
||||||
-d decode"""
|
System.lineSeparator() + " -d decode"
|
||||||
|
|
||||||
// see https://www.rfc-editor.org/rfc/rfc3986#page-13
|
// see https://www.rfc-editor.org/rfc/rfc3986#page-13
|
||||||
private val unreservedChars = BitSet('~'.code + 1).apply {
|
private val unreservedChars = BitSet('~'.code + 1).apply {
|
||||||
|
@ -205,17 +205,15 @@ Encode and decode URL parameters.
|
||||||
|
|
||||||
internal fun processMain(args: Array<String>): MainResult {
|
internal fun processMain(args: Array<String>): MainResult {
|
||||||
val result = MainResult()
|
val result = MainResult()
|
||||||
if (args.isNotEmpty() && args[0].isNotBlank()) {
|
if (args.isNotEmpty() && args[0].isNotBlank() && args.size <= 2) {
|
||||||
val hasDecode = args[0] == "-d"
|
val hasDecode = args[0] == "-d"
|
||||||
val hasOption = hasDecode || args[0] == "-e"
|
val hasOption = hasDecode || args[0] == "-e"
|
||||||
if (!hasOption || args.size >= 2) {
|
if (!hasOption || args.size == 2) {
|
||||||
val argsList = mutableListOf<String>()
|
val arg = if (hasOption) args[1] else args[0]
|
||||||
argsList.addAll(args)
|
|
||||||
if (hasOption) argsList.removeAt(0)
|
|
||||||
if (hasDecode) {
|
if (hasDecode) {
|
||||||
result.output = decode(argsList.joinToString(" "))
|
result.output = decode(arg)
|
||||||
} else {
|
} else {
|
||||||
result.output = encode(argsList.joinToString(" "))
|
result.output = encode(arg)
|
||||||
}
|
}
|
||||||
result.status = 0
|
result.status = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ class UrlEncoderTest {
|
||||||
@Test
|
@Test
|
||||||
fun testMainUsage() {
|
fun testMainUsage() {
|
||||||
var result: UrlEncoder.MainResult
|
var result: UrlEncoder.MainResult
|
||||||
|
assertEquals(usage, processMain(arrayOf("foo", "bar", "test")).output, "too many args")
|
||||||
for (arg in arrayOf("", " ", "-d", "-e")) {
|
for (arg in arrayOf("", " ", "-d", "-e")) {
|
||||||
result = processMain(arrayOf(arg))
|
result = processMain(arrayOf(arg))
|
||||||
assertEquals(usage, result.output, "processMain('$arg')")
|
assertEquals(usage, result.output, "processMain('$arg')")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue