hertz icon indicating copy to clipboard operation
hertz copied to clipboard

[WIP]appendMw: use minimal numeric suffix for unique names

Open srpvpn opened this issue 5 months ago • 3 comments

What type of PR is this?

  • [x] fix

Check the PR title.

  • [x] This PR title matches the format: fix(appendMw): generate sequential middleware names
  • [x] 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 avatar Aug 07 '25 20:08 srpvpn

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 07 '25 20:08 CLAassistant

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

HeyJavaBean avatar Aug 11 '25 06:08 HeyJavaBean

@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 avatar Aug 30 '25 21:08 srpvpn