Inefficient regex in `extract_full_summary_from_signature`
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- cli, performance
调研方向
从 knack/introspection.py 中第 18 行附近的 extract_full_summary_from_signature regex 开始。重现 issue 中所示的长空格输入和格式错误输入,然后验证参数文档仍能正确提取,同时病态输入不再导致过度回溯。所提出的 regex 和示例定义了预期行为。
由索引模型根据 Issue 内容生成。
描述
As pointed out by https://gist.github.com/prodigysml/d07cd482214c80bfb6d3240454d2f679, this regex (introduced by https://github.com/microsoft/knack/commit/430c39e657d8a424ef9b631782fe0e62a6bed203, #8) is inefficient:
It tries to match a string such as:
:param command_loader: The command loader that commands will be registered into
As shown in https://regex101.com/, a simple :param r requires 1214 steps to fail.
:param r causes catastrophic backtracking:
This is because \s+, .+? and \s* all match consecutive spaces, thus can trigger many backtrackings.
A better solution is to replace .+? with \w+ to match the parameter name so that backtrackings can be greatly reduced:
\s*(:param)\s+(\w+)\s*:(.*)
- 主要语言
- Python
- 星标
- 359
- 派生
- 104
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/knack 的其他 Issue
-
UnicodeEncodeError fallback discards all non-ASCII output, including characters the target encoding supports可能已有人在做 @kimsey0 于 87 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 10/100
-
Request to add support for handling bytearray when outputting data in YAML format可能已有人在做 @Shubham-Padkonde 于 48 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 48/100
-
Broken `examples/test_exapp`: TypeError: ScenarioTest.__init__() missing 1 required positional argument: 'method_name'可能已有人在做 @jiasli 于 845 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 48/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
-
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 7 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 78/100
MTSWebServices/RecTools#330 ·
-
area: web priority: P1 story
难度 2/5 1-3 小时 新手友好度 76/100
nfiasco/Quant-Time-Machine#151 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
autowarefoundation/autoware_carla_scenario#2019 ·
维护者通常 1 天内回复