Repository navigation
fix(template): avoid catastrophic backtracking in table-mode detection - #314
Merged
smalluban merged 1 commit intoSep 17, 2026
Merged
Conversation
The regex that decides whether a placeholder sits inside an open table tag allowed a quote to be consumed either as a plain character or as the start of a quoted string, so a failed match had to try every pairing of quotes: 2^n for n tags with two quoted attributes after a table tag with an attribute. A template with a data table followed by a form with a few dozen attributed tags never finished compiling. Excluding quotes from the plain-character branch makes the alternatives mutually exclusive; the decision is unchanged for all table cases. Closes hybridsjs#313
smalluban
approved these changes
Sep 17, 2026
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.
Fixes #313.
createContents()tests the accumulated static template text at every placeholder against the table-mode regex. Its group([^<>]|"[^"]*"|'[^']*')*let a quote be consumed either as a plain character or as the start of a quoted string, and a quoted string may span<and>. When the match fails, the engine tries every pairing of quotes: 2^n for n tags with two quoted attributes following a table tag with an attribute (see the timings in #313; a data table followed by a tabbed form never finished compiling).This change excludes quotes from the plain-character branch (
[^<>"']), which makes the three alternatives mutually exclusive, so the engine has exactly one path. The regex decides identically for every table case in the suite (<table>,<table class="x">,<td class="num">,<th title='a > b'>,<thead-element>, closed tables, text after a tag).Regression test: a table with a quoted attribute followed by 24 attributed buttons and an expression must render in under a second. Against the current regex it takes about 3.4 s in Chrome Headless and fails; with the fix it takes 0 ms. Full suite: 602 of 602 passing, lint and prettier clean.