Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同一组规则中若干条规则会互相影响,v2.4.6 #382

Closed
WavinFlag opened this issue Jan 13, 2020 · 4 comments
Closed

同一组规则中若干条规则会互相影响,v2.4.6 #382

WavinFlag opened this issue Jan 13, 2020 · 4 comments

Comments

@WavinFlag
Copy link
Contributor

line`
https://example.com/
http://localhost:3000/
enable://intercept
`

line`
https://cdn.example.com/path/to/project/
http://localhost:3000/
enable://intercept
`

形如上述的两条路径替换规则无法同时生效,具体地只有第一条会生效。

这里的匹配模式是“(前缀)路径匹配”,实际上换成“通配符匹配”也一样有问题。

顺便,匹配原则是不是搞得太复杂了?(或者概念和架构并不清晰)

@WavinFlag
Copy link
Contributor Author

我又尝试修改匹配条件、修改规则顺序、修改规则添加先后,发现完全没有明确的规律;一组规则,经过若干次变动后回到原先状态,甚至都无法得到相同的结果。

怀疑 ruleset 的编译和加载环节出现问题。

@avwo
Copy link
Owner

avwo commented Jan 14, 2020

  1. 建议你先开启全局捕获 https 请求,不要每个请求同通过 enable://intercept 开启,单个请求开启只支持域名匹配的方式 (example.com enable://inercept)
  2. 规则的默认匹配顺序是从上到下,更精确的匹配应该放在上面;有些规则如 url 替换 只能一个生效,自己想想两个同时生效会是什么样的效果?
  3. 规则肯定是按上述规律执行,先理清下你的步骤,看下哪个配置环节出现差异
  4. 其它的如果有更好的建议可以提出来,不要光吐槽,拿出自己的解决方案

@WavinFlag
Copy link
Contributor Author

问题我找到了。
bug 的表现是:两个连续的多行规则之间,如果有任意空行(且仅有空行),就会产生解析错误;两条多行规则会被解析到一起。
举个例子:

line`
A1
A2
`

line`
B1
B2
`

会被解析为 A1 A2B1 B2,而非预期的 A1 A2\nB1 B2

与 bug 相关的代码是这几行:

var MULTI_TO_ONE_RE = /^\s*line`\s*[\r\n]([\s\S]*?)[\r\n]\s*`\s*$/mg;

text = text.replace(MULTI_TO_ONE_RE, toLine);

MULTI_TO_ONE_RE 头尾的 \s* 会匹配掉前后的空行(换行),在 multi 模式的正则替换时,会产生重复替换。那为什么两条多行规则间没有空行时不会重复替换呢?因为这时唯一的 \n 被解释为matching 的多行边界。

已提 PR #383

@avwo
Copy link
Owner

avwo commented Jan 14, 2020

重新安装 whistle ,并重启

@avwo avwo closed this as completed Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants