Open jiasli opened 5 months ago
As pointed out by https://gist.github.com/prodigysml/d07cd482214c80bfb6d3240454d2f679, this regex (introduced by https://github.com/microsoft/knack/commit/430c39e657d8a424ef9b631782fe0e62a6bed203) is inefficient:
https://github.com/microsoft/knack/blob/e0c14114aea5e4416c70a77623e403773aba73a8/knack/introspection.py#L18
As shown in https://regex101.com/, a simple :param r requires 1214 steps to fail.
:param r
This is because \s+, .+? and \s* all match consecutive spaces, thus can trigger many backtrackings.
\s+
.+?
\s*
A better solution is to replace .+? with \w+ to match the parameter name so that backtrackings can be greatly reduced:
\w+
\s*(:param)\s+(\w+)\s*:(.*)
As pointed out by https://gist.github.com/prodigysml/d07cd482214c80bfb6d3240454d2f679, this regex (introduced by https://github.com/microsoft/knack/commit/430c39e657d8a424ef9b631782fe0e62a6bed203) is inefficient:
https://github.com/microsoft/knack/blob/e0c14114aea5e4416c70a77623e403773aba73a8/knack/introspection.py#L18
As shown in https://regex101.com/, a simple
:param r
requires 1214 steps to fail.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: