Closed
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
7.2.3
Link to runnable example
No response
Steps to reproduce
import {raw} from 'hast-util-raw'
import {u} from 'unist-builder'
let test1 = u('root', [
u('raw', '<xmp><b>bold</b>after</xmp>'),
])
let test2 = u('root', [
u('raw', '<xmp>'),
u('raw', '<b>'),
u('text', 'bold'),
u('raw', '</b>'),
u('text', 'after'),
u('raw', '</xmp>'),
])
console.log(raw(test1))
console.log(raw(test2))
Expected behavior
The output tree should contain:
- root
- element:
xmp
- text: "<b>bold</b>after"
- element:
(note: <xmp> is parsed in RAWTEXT mode, so tags/escapes aren't parsed inside it, and it only ends when the parser reaches </xmp>
)
Actual behavior
- root
- element:
xmp
- text: "<b>bold"
- text: "after"
- element:
the <xmp> element is being closed by the </b> tag
This affects all elements whose contents are parsed as RAWTEXT/SCRIPT_DATA (<style>, <iframe>, <noembed>, <noframes>, <script>) or RCDATA (<title>, <textarea>)
This can be seen in remark/rehype (with allowDangerousHtml enabled), in cases like:
<xmp><b>one</b><b>two</b></xmp>
which renders as:
<b>onetwo
Affected runtime and version
Affected package manager and version
Affected OS and version
Debian
Build and bundle tools
Rollup