Skip to content

fix: stop appending a stray '<' to unterminated block-text elements - #313

Merged
taoqf merged 1 commit into
taoqf:mainfrom
spokodev:fix/unterminated-block-text-stray-lt
Sep 3, 2026
Merged

fix: stop appending a stray '<' to unterminated block-text elements#313
taoqf merged 1 commit into
taoqf:mainfrom
spokodev:fix/unterminated-block-text-stray-lt

Conversation

@spokodev

@spokodev spokodev commented Jul 8, 2026

Copy link
Copy Markdown

An unterminated raw-text element (script/style/pre) with no closing tag keeps a stray < in its text:

parse('<script>var a = 1;', { script: true }) // text 'var a = 1;<'  (expected 'var a = 1;')
parse('<style>.a{color:red}')                 // text '.a{color:red}<'

dataEndPos was computed from the opening wrapper length, but the closing sentinel is one character longer, so the < of the sentinel was included when the element has no closing tag. Off by one in the EOF branch.

@taoqf taoqf left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. unterminated block-text elements
    does not append a stray "<" to an unclosed <script>:

    AssertionError: expected 'var a = 1;<' to equal 'var a = 1;'

    • expected - actual

    -var a = 1;<
    +var a = 1;

    at Assertion.fail (test/node_modules/should/cjs/should.js:275:17)
    at Assertion.value (test/node_modules/should/cjs/should.js:356:19)
    at Context. (test/tests/incomplete-blocktext.js:8:22)
    at process.processImmediate (node:internal/timers:504:21)

  2. unterminated block-text elements
    does not append a stray "<" to an unclosed <style>:

    AssertionError: expected '.a{color:red}<' to equal '.a{color:red}'

    • expected - actual

    -.a{color:red}<
    +.a{color:red}

    at Assertion.fail (test/node_modules/should/cjs/should.js:275:17)
    at Assertion.value (test/node_modules/should/cjs/should.js:356:19)
    at Context. (test/tests/incomplete-blocktext.js:14:21)
    at process.processImmediate (node:internal/timers:504:21)

@spokodev

spokodev commented Sep 1, 2026

Copy link
Copy Markdown
Author

This passes once dist/ is rebuilt from the branch — test:dist runs against the compiled dist/, which the test/pretest scripts don't recompile, so a stale build still shows the trailing <. On current main with this change, bun run build && bun run test:dist gives 267 passing (0 failing), including both unterminated block-text elements cases, and the dataEndPos change causes no other regressions.

When a block-text element (script, style, pre, ...) has no closing tag,
the text-end position fell back to dataEndPos, which subtracted the
length of the *opening* frame-flag wrapper (frameflag.length + 2) rather
than the *closing* one (frameflag.length + 3). The resulting off-by-one
included the leading '<' of the internal </documentfragmentcontainer>
sentinel, so parsing '<script>var a = 1;' produced text 'var a = 1;<'.
@spokodev
spokodev force-pushed the fix/unterminated-block-text-stray-lt branch from 90a82c9 to 48300fe Compare September 2, 2026 08:50
@spokodev

spokodev commented Sep 2, 2026

Copy link
Copy Markdown
Author

Rebased onto main — CI is green now (build 22/24/26.x). The earlier red was a stale base (the old yarn lockfile), not the change itself. Ready for another look.

@taoqf
taoqf merged commit 5268108 into taoqf:main Sep 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants