Skip to content

fix: reject duplicate param names in route registration#1513

Open
Lcos-000 wants to merge 1 commit into
cloudwego:mainfrom
Lcos-000:fix/duplicate-param-check
Open

fix: reject duplicate param names in route registration#1513
Lcos-000 wants to merge 1 commit into
cloudwego:mainfrom
Lcos-000:fix/duplicate-param-check

Conversation

@Lcos-000

Copy link
Copy Markdown
Contributor

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

fix: 路由注册时拒绝重复参数名

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
When a route contains duplicate parameter names in different path segments, such as /user/:id/order/:id, Params.ByName("id") always returns the first matched value. As a result, the later parameter value cannot be retrieved, which may lead to subtle and hard-to-debug issues.

This PR adds checkDuplicateParams to detect and reject such routes during registration, with a clear panic message. This makes invalid route definitions fail fast instead of causing unexpected runtime behavior.

zh:
当路由在不同路径段中包含重复参数名时,例如 /user/:id/order/:idParams.ByName("id") 始终只会返回第一个匹配到的值,后续同名参数的值无法获取。这可能导致隐蔽且难以排查的问题。

本 PR 新增 checkDuplicateParams,在路由注册阶段检测并拒绝此类路由,并给出明确的 panic 信息。这样可以让非法路由定义尽早失败,避免运行时出现非预期行为。

(Optional) Which issue(s) this PR fixes:

(Optional) The PR that updates user documentation:

@Lcos-000 Lcos-000 requested review from a team as code owners June 12, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant