ktorio / ktorio/ktor

Routing doesn't merge routes with different parameter names

Open
#549 2 comments 0 reactions 0 assignees View on GitHub
routing ux
Dominant language
Kotlin
Stars
14.5k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
49

Description

Example 1a
```kotlin
get("/{...}") {
println("first")
}
get("/{...}") {
println("second")
}
```

Example 2b

```kotlin
get("/{param...}") {
println("first")
}
get("/{param...}") {
println("second")
}
```

Accessing `/` or `/path` causes both handlers to print to the system output.

However changing parameter names makes it work completely different

Example 2
```kotlin
get("/{param1...}") {
println("first")
}
get("/{param2...}") {
println("second")
}
```

In this case only first handler is invoked while the second handler is filtered out.

The reason why it works like that is that in examples 1a and 1b both routes get merged into one so both handlers are actually added to a single route instance. In example 2 we have two different routes so route resolution takes the first one due to ambiguity.

The particular consequence of this issue is that user are unable to write custom directory index pages unlike they know exact parameter name that is private inside of static content routes implementation.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two route-registration examples and requests to `/` and `/path`, then trace the routing merge and resolution behavior for parameterized paths. Done means routes with different parameter names no longer cause the second handler to be filtered out, while the existing same-name behavior remains understood and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.