LiteParser fails to parse opening tags when attributes are separated by CRLF, tab, or form-feed
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Issue Summary
LiteParser currently does not recognize all HTML ASCII whitespace characters while matching serialized HTML tags.
In particular, an opening tag like this:
<mjx-container
class="MathJax">x</mjx-container>
where the line break between the tag name and the attribute is CRLF (\r\n) is not parsed as an element. Instead, the opening tag is treated as text, and only the closing tag is matched later.
This can happen when serialized HTML contains Windows-style CRLF line endings inside tags.
Steps to Reproduce:
const {strict: assert} = require('node:assert');
const {liteAdaptor} = require('@mathjax/src/js/adaptors/liteAdaptor.js');
const {LiteParser, PATTERNS} = require('@mathjax/src/js/adaptors/lite/Parser.js');
const input = '<mjx-container\r\nclass="MathJax">x</mjx-container>';
const firstMatchedTag = input.match(PATTERNS.tag)?.[0];
console.log('first matched tag:', JSON.stringify(firstMatchedTag));
const adaptor = liteAdaptor();
const doc = new LiteParser().parseFromString(input, 'text/html', adaptor);
const body = adaptor.body(doc);
const child = adaptor.childNodes(body)[0];
console.log('parsed body:', adaptor.outerHTML(body));
console.log('first child kind:', child && adaptor.kind(child));
assert.equal(
adaptor.kind(child),
'mjx-container',
'opening tag with CRLF should be parsed as an element'
);
assert.equal(adaptor.getAttribute(child, 'class'), 'MathJax');
assert.equal(adaptor.textContent(child), 'x');
console.log('PASS');
Actual behavior
The opening tag is not matched as a tag. It is parsed as text:
first matched tag: "</mjx-container>"
parsed body: <body><mjx-container
class="MathJax">x</body>
first child kind: #text
So the assertion fails because the first child is a text node rather than an mjx-container element.
Expected behavior
The opening tag should be recognized as an element tag, and the parsed result should be equivalent to:
<body><mjx-container class="MathJax">x</mjx-container></body>
Expected output:
first matched tag: "<mjx-container\r\nclass=\"MathJax\">"
parsed body: <body><mjx-container class="MathJax">x</mjx-container></body>
first child kind: mjx-container
PASS
Technical details:
- MathJax Version: 4.1.3
- Client OS: Windows
Supporting information:
Related mathjax/Mathjax-src#1521
[1] ASCII whitespace https://infra.spec.whatwg.org/#ascii-whitespace
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in @mathjax/src/js/adaptors/lite/Parser.js, especially the PATTERNS.tag entry, and reproduce the issue with the provided LiteParser example. Verify that opening tags with CRLF, tab, and form-feed between the tag name and attributes are recognized as elements, with the shown attributes and text preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100