Skip to content

Conversation

@srpvpn
Copy link

@srpvpn srpvpn commented Aug 7, 2025

What type of PR is this?

  • fix

Check the PR title.

  • This PR title matches the format: fix(appendMw): generate sequential middleware names
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • N/A – no user-facing docs need updating.

(Optional) Translate the PR title into Chinese.

修复(appendMw): 顺序生成中间件唯一名称

@srpvpn srpvpn requested review from a team as code owners August 7, 2025 20:09
@CLAassistant
Copy link

CLAassistant commented Aug 7, 2025

CLA assistant check
All committers have signed the CLA.

@HeyJavaBean
Copy link
Member

感谢。能否补充下对应问题的复现场景并且补充单测~

@jayantxie jayantxie changed the title appendMw: use minimal numeric suffix for unique names [WIP]appendMw: use minimal numeric suffix for unique names Aug 18, 2025
@srpvpn
Copy link
Author

srpvpn commented Aug 30, 2025

@HeyJavaBean
感谢您的反馈!

问题复现场景

原来的 appendMw 函数有一个严重的bug:它会直接修改输入参数 mw,导致生成错误的中间件名称。

例如,当存在 ["mw"] 时:

  • 第一次循环:mw = "mw" → 已存在 → mw += "0" → mw = "mw0"
  • 第二次循环:mw = "mw0" → 已存在 → mw += "1" → mw = "mw01"
  • 第三次循环:mw = "mw01" → 已存在 → mw += "2" → mw = "mw012"

这生成了无意义的名称如 "mw01", "mw012" 而不是正确的 "mw0", "mw1", "mw2"。

修复方案:

  • 保存原始名称到 base 变量
  • 不修改输入参数
  • 生成正确的序列:mw → mw1 → mw2 → mw3

单元测试:
现有的测试文件 router_appendmw_test.go 已经覆盖了这些场景,确保修复后的逻辑正确工作。

@srpvpn
Copy link
Author

srpvpn commented Dec 30, 2025

Hi @HeyJavaBean , gentle reminder about this PR. I've addressed the feedback on tests and reproduction. Is there anything else needed? Thanks!

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.

3 participants