⚡✅ Update more regexps to run in linear time #147
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I didn't have time to look closely at these when I pushed #145. For that PR, I prioritized
BEG_REGEXP
because it is used all the time, with unconstrained input. These other regexps are only used whenNet::IMAP.debug = truthy
or bysaslprep
, which is only used by the SCRAM-SHA-256 SASL mechanism, which isn't even merged yet, oops! (See #54, #78)So this fixes both of those.
For the debug output gsub, the same string transform is simple to accomplish without negative lookahead by using a block with gsub and checking
$'.empty?
. I don't believeNet::IMAP.debug
has any tests, but 1) I did test it manually, and 2) I intend to push a PR that changes how strings are validated, generated, and sent. The updated output will also change (simplify) this debug output, allowing redaction of passwords and authentication tokens, and come with its own tests.For
StringPrep::SASLprep::BIDI_FAILURE
and the other related regexps, they all used\g<name>
to define char classes and then re-use them. Unfortunately, ruby 3.2 can't compile\g<...>
to run in linear time. The regexps can also be shortened by using lookahead, but that also can't run in linear time. Although this expands theBIDI_FAILURE
regexp to ~15Kb, it slightly simplifies the generation.