KTOR-8199 Decode URL-encoded path before matching watch patterns#5586
KTOR-8199 Decode URL-encoded path before matching watch patterns#5586osipxd merged 1 commit intoktorio:mainfrom
Conversation
📝 WalkthroughWalkthroughThe PR enhances URL matching robustness by updating ChangesURL Path Decoding Enhancement
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ktor-server/ktor-server-core/jvm/test/io/ktor/server/engine/EmbeddedServerTest.kt (1)
2-2: 💤 Low valueUpdate copyright year to 2025.
The copyright year in this file shows 2024, while the main source file uses 2025. Consider updating for consistency.
♻️ Proposed fix
-/* - * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ +/* + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ktor-server/ktor-server-core/jvm/test/io/ktor/server/engine/EmbeddedServerTest.kt` at line 2, Update the copyright year in EmbeddedServerTest.kt from 2014-2024 to 2014-2025 to match the main source files; open the file (EmbeddedServerTest.kt) and edit the header comment line that currently contains "Copyright 2014-2024" so it reads "Copyright 2014-2025".ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/EmbeddedServerJvm.kt (1)
496-496: ⚡ Quick winPrefer
Charsets.UTF_8over string literal.Use the
Charsets.UTF_8constant instead of the string literal"utf-8"for better type safety and consistency with Kotlin conventions.♻️ Proposed fix
- val urlPath = URLDecoder.decode(rawPath, "utf-8").replace(File.separatorChar, '/') + val urlPath = URLDecoder.decode(rawPath, Charsets.UTF_8.name()).replace(File.separatorChar, '/')Or if using Kotlin 1.5+, you can use the extension function:
- val urlPath = URLDecoder.decode(rawPath, "utf-8").replace(File.separatorChar, '/') + val urlPath = rawPath.decodeURLQueryComponent().replace(File.separatorChar, '/')Note: The second option requires
import io.ktor.http.decodeURLQueryComponentfrom ktor-http, which is already imported in this file (line 9).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/EmbeddedServerJvm.kt` at line 496, Replace the string literal "utf-8" in the URL decoding call with the Kotlin charset constant to follow conventions: update the URLDecoder.decode(rawPath, "utf-8") usage (in the urlPath assignment in EmbeddedServerJvm.kt) to use Charsets.UTF_8 (or, if you prefer the ktor helper, call the existing decodeURLQueryComponent extension on rawPath) so the charset is type-safe and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/EmbeddedServerJvm.kt`:
- Line 496: Replace the string literal "utf-8" in the URL decoding call with the
Kotlin charset constant to follow conventions: update the
URLDecoder.decode(rawPath, "utf-8") usage (in the urlPath assignment in
EmbeddedServerJvm.kt) to use Charsets.UTF_8 (or, if you prefer the ktor helper,
call the existing decodeURLQueryComponent extension on rawPath) so the charset
is type-safe and consistent.
In
`@ktor-server/ktor-server-core/jvm/test/io/ktor/server/engine/EmbeddedServerTest.kt`:
- Line 2: Update the copyright year in EmbeddedServerTest.kt from 2014-2024 to
2014-2025 to match the main source files; open the file (EmbeddedServerTest.kt)
and edit the header comment line that currently contains "Copyright 2014-2024"
so it reads "Copyright 2014-2025".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 58cbaaa9-1e47-4e76-8b4d-afb90deb1375
📒 Files selected for processing (2)
ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/EmbeddedServerJvm.ktktor-server/ktor-server-core/jvm/test/io/ktor/server/engine/EmbeddedServerTest.kt
Subsystem
Server, Auto-reload
Motivation
KTOR-8199 Autoreloading: default watch patterns don't match anything when project path contains spaces
The default watch pattern is
WORKING_DIRECTORY_PATH = SystemFileSystem.resolve(Path(".")).toString(), which preserves literal characters from the filesystem path (e.g. a space when the project lives under/Users/me/my project/...). The classpath URLs passed tocheckUrlMatchesexpose their path in URL-encoded form (/Users/me/my%20project/build/...), so the substring match always fails and the engine logs:The same file already URL-decodes the path inside
watchUrls()(URLDecoder.decode(path, "utf-8")), so the encoded-vs-decoded mismatch was inconsistent within the same module.Solution
Decode
url.pathbefore normalizing separators and matching against the pattern, mirroring the existingwatchUrls()call site. The fix generalizes to any URL-encoded segment, not just spaces.