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

KTOR-4669 Encode Content-Disposition filename* parameter #3110

Merged
merged 3 commits into from Jul 26, 2022
Merged

Conversation

e5l
Copy link
Member

@e5l e5l commented Jul 21, 2022

Fix KTOR-4669

@e5l e5l requested a review from rsinukov July 21, 2022 08:13
@e5l e5l self-assigned this Jul 21, 2022
* Characters allowed in attributes according: https://datatracker.ietf.org/doc/html/rfc5987
* attr-char = ALPHA / DIGIT / "!" / "#" / "$" / "&" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
*/
internal val ATTRIBUTE_CHARACTERS: Set<Char> = (URL_ALPHABET_CHARS + listOf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listOf -> setOf and then you don't need toSet

@@ -120,6 +128,27 @@ public fun String.encodeURLParameter(
}
}

internal fun String.percentEncode(allowedSet: Set<Char>): String {
val encodedCount = count { it !in allowedSet }
val resultSize = length + encodedCount * 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add an early return here if count is 0?

@rsinukov
Copy link
Contributor

Please check code style and API

@e5l e5l merged commit 26028bc into main Jul 26, 2022
@e5l e5l deleted the e5l/filename-fix branch July 26, 2022 05:54
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.

None yet

2 participants