Opus advisor review of stage-375 flagged that the protected-bracket set including `<` and `>` caused tables containing comparison operators across adjacent columns to mis-collapse: `| x < 5 | y > 10 |` matched `< ... >` as a bracket pair and stashed the inner pipe, producing one cell instead of two. Real LLM table output uses angle brackets as comparison operators far more often than as content-grouping pairs, so the safer default is to NOT treat them as a matched pair. Dropped `<` from the opener class and `>` from both closer classes. Three regression tests added (`TestComparisonOperatorsAcrossColumns` class): `< … >` across columns, `<` alone, `>` alone.
This commit is contained in:
@@ -2724,7 +2724,10 @@ function renderMd(raw){
|
||||
// are written as hex escapes (\x7b and \x7d) so the JS source contains no
|
||||
// bare brace glyphs that would confuse the brace-counting extractFunc in
|
||||
// tests/test_renderer_js_behaviour.py. Regex semantics are identical.
|
||||
const _protectPipes=r=>{let prev;do{prev=r;r=r.replace(/([([\x7b<][^)\]\x7d>]*)[|]([^)\]\x7d>]*[)\]\x7d>])/g,(_,a,b)=>a+'\x00PIPE\x00'+b);}while(r!==prev);return r;};
|
||||
// Bracket set is paren / square / curly only -- NOT angle brackets, since
|
||||
// angle brackets are overwhelmingly comparison operators in real LLM table
|
||||
// output (`| x < 5 | y > 10 |`) and treating them as a pair collapses cells.
|
||||
const _protectPipes=r=>{let prev;do{prev=r;r=r.replace(/([([\x7b][^)\]\x7d]*)[|]([^)\]\x7d]*[)\]\x7d])/g,(_,a,b)=>a+'\x00PIPE\x00'+b);}while(r!==prev);return r;};
|
||||
const _restorePipes=s=>s.replace(/\x00PIPE\x00/g,'|');
|
||||
const parseRow=r=>{r=_protectPipes(r);return r.trim().replace(/^\|/,'').replace(/\|$/,'').split('|').map(c=>`<td>${inlineMd(_restorePipes(c.trim()))}</td>`).join('');};
|
||||
const parseHeader=r=>{r=_protectPipes(r);return r.trim().replace(/^\|/,'').replace(/\|$/,'').split('|').map(c=>`<th>${inlineMd(_restorePipes(c.trim()))}</th>`).join('');};
|
||||
|
||||
@@ -215,3 +215,31 @@ class TestKatexDollarInTableCell:
|
||||
f"`$5 | $10` must remain two cells, not collapse to one math span. "
|
||||
f"Got {len(cells)} cells: {cells!r}"
|
||||
)
|
||||
|
||||
|
||||
class TestComparisonOperatorsAcrossColumns:
|
||||
"""The first cut of #2428 included `<` and `>` in the protected-bracket
|
||||
set. That caused tables containing comparison operators across adjacent
|
||||
columns to mis-collapse: ``| x < 5 | y > 10 |`` matched `< … >` as a
|
||||
bracket pair and stashed the inner pipe, producing one cell instead of
|
||||
two. Stage-fix removed `<` / `>` from the bracket set because real LLM
|
||||
output uses angle brackets as comparison operators far more often than
|
||||
as a content-grouping pair."""
|
||||
|
||||
def test_less_than_greater_than_across_columns_stays_two_cells(self, driver_path):
|
||||
md = "| x < 5 | y > 10 |\n|---|---|\n| less | more |"
|
||||
cells = _table_cells(_render(driver_path, md))
|
||||
assert len(cells) == 4, (
|
||||
f"`| x < 5 | y > 10 |` must produce 4 cells (2 cols × 2 rows). "
|
||||
f"Got {len(cells)} cells: {cells!r}"
|
||||
)
|
||||
|
||||
def test_less_than_alone_in_cell(self, driver_path):
|
||||
md = "| a < b | c |\n|---|---|\n| ok | y |"
|
||||
cells = _table_cells(_render(driver_path, md))
|
||||
assert len(cells) == 4, f"got cells: {cells!r}"
|
||||
|
||||
def test_greater_than_alone_in_cell(self, driver_path):
|
||||
md = "| a > b | c |\n|---|---|\n| ok | y |"
|
||||
cells = _table_cells(_render(driver_path, md))
|
||||
assert len(cells) == 4, f"got cells: {cells!r}"
|
||||
|
||||
Reference in New Issue
Block a user