Repository navigation
Conversation
The `[^\\]*?` group for the abbreviation in `AbbrBlockprocessor.RE` also matches newlines, so a line starting with `*[` which is not a definition is read on to the next `]:` further down the block. The lines in between become part of the abbreviation and are dropped from the output, and the definition (or link reference) on the later line is lost. When no `]:` follows, every line starting with `*[` is scanned to the end of the block, so n of them take O(n^2) time. Before 9edba85 the group was `[^\]]*`, which stopped at the first `]`. Excluding newlines instead keeps `]` and `^` allowed in an abbreviation and limits each attempt to its own line, as the line-based preprocessor this replaced did. A title on the following line is still matched by the rest of the pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
AbbrBlockprocessor.REmatches the abbreviation with[^\\]*?, which also matches newlines, andtestaccepts any block. So withabbr(orextra) enabled, a line which starts with*[but is not a definition is read on to the next]:further down the same block:The first line is dropped and
HTMLis not defined. The abbreviation recorded instead is'sic]* marks a quoted error.\n*[HTML'. A link reference definition on the later line is lost the same way. When no]:follows, every line starting with*[is scanned to the end of the block, so the time is quadratic in the number of such lines:Before 9edba85 the class excluded
], so a match stopped at the first]and a line such as*[sic]*could not run on into the next one. Excluding newlines instead keeps]and^allowed in an abbreviation and limits each attempt to its own line, as the line-based preprocessor which the block processor replaced did. A title on the following line (test_abbr_line_break) still works. The one change in behavior is that an abbreviation whose name is split over two lines is no longer a definition.The old and new regex give the same
searchandfinditermatches on every string up to length 9 over*,[,],:, space,a, newline and backslash, plus 300,000 random strings, except where the old match's abbreviation spans lines. Rendered HTML and recorded abbreviations match master on 200,000 random documents (withabbr,extra, andextraplustoc,admonition,sane_lists,smartyandnl2br) except the 3,649 in which master matched a multi-line abbreviation.This is separate from #1702, which takes consecutive definitions in one pass. The scan above happens inside a single search, and
finditerhas the same problem. #1702's code change applies cleanly on top of this one (only the changelog entry conflicts), its tests pass, and the 156 KiB input takes 0.3 s with both.The first new test fails on master. The second takes 13.4 s on master and 0.09 s with this change.
AI Assistance Disclosure
No AI tools were used in preparing this PR.
AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.
AI tools were use to assist with the following:
Checklist