fix: reject duplicate param names in route registration#1513
Open
Lcos-000 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
fix
Check the PR title.
(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
checkDuplicateParamsto 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/:id,Params.ByName("id")始终只会返回第一个匹配到的值,后续同名参数的值无法获取。这可能导致隐蔽且难以排查的问题。本 PR 新增
checkDuplicateParams,在路由注册阶段检测并拒绝此类路由,并给出明确的 panic 信息。这样可以让非法路由定义尽早失败,避免运行时出现非预期行为。(Optional) Which issue(s) this PR fixes:
(Optional) The PR that updates user documentation: