3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Refuse a pipe table whose padding would add more cells than the table holds

This commit is contained in:
2026-11-10 17:03:53 +01:00
committed by Lillem4n
parent 3b61501fe2
commit 785388d426
6 changed files with 32 additions and 7 deletions
+9
View File
@@ -551,6 +551,15 @@ function pipeTableBlock(rows: readonly [string[], ...string[][]], position: Sour
const padsShortRows = claims.pipeTables === 'gfm'
const ragged = [delimiter, ...body].find((row) => (padsShortRows && row !== delimiter ? row.length > header.length : row.length !== header.length))
if (ragged !== undefined) return faultedBlock(`a pipe table row holds ${cellCount(ragged.length)} where its header holds ${cellCount(header.length)}`, position)
let held = header.length + delimiter.length
let padding = 0
for (const row of body) {
held += row.length
padding += header.length - row.length
}
if (padding > held) {
return faultedBlock(`a pipe table's short rows would pad ${cellCount(padding)}, more than the ${cellCount(held)} it holds: write the empty cells out`, position)
}
const padded = body.map((row) => [...row, ...Array.from({ length: header.length - row.length }, () => '')])
return { kind: 'table', position, rows: [header, ...padded] }
}