Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): fix invalid encoding of scopes in query parameters #976

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

stnguyen90
Copy link
Contributor

What does this PR do?

Before this, the it.value.toString() caused the list of scopes to be encoded like scopes[]=[scope1, scope2] which is invalid.

This change fixes the encoding to scopes[]=scope1&scopes[]=scope2 as expected by the server.

Test Plan

Tested running this code:

fun main() {
    val apiParams = mutableMapOf<String, Any?>(
        "scopes" to listOf("user.read", "user.write"),
    )
    val apiQuery = mutableListOf<String>()
    apiParams.forEach {
        when (it.value) {
            null -> {
                return@forEach
            }
            is List<*> -> { 
                (it.value as List<*>).forEach { v ->
                    apiQuery.add("${it.key}[]=${v.toString()}")
                }
            }
            else -> {
               apiQuery.add("${it.key}=${it.value.toString()}")
            }
        }
    }

    print(apiQuery)
}

in Kotlin playground:

image

Related PRs and Issues

Have you read the Contributing Guidelines on issues?

Yes

Before this, the `it.value.toString()` caused the list of scopes to be
encoded like `scopes[]=[scope1, scope2]` which is invalid.

This change fixes the encoding to `scopes[]=scope1&scopes[]=scope2` as
expected by the server.
@stnguyen90 stnguyen90 merged commit 2dd681f into master Sep 17, 2024
34 checks passed
@stnguyen90 stnguyen90 deleted the fix-60-invalid-scopes branch September 17, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants