Repository navigation
Conversation
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
|
@hakarrr is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
The raw value of tokens should ideally be the value of the markdown that rendered that token. If we replace it in the lexer raw will contain the replaced value instead |
|
Agreed, this also changes token.raw, and I missed that API effect in the tests. I'll add raw-preservation coverage and check a tokenizer-level approach before updating the PR. The current lexer-wide replacement shouldn't be treated as ready. |
|
I tested keeping NULs through tokenization and replacing them in token text afterward. That preserves raw for built-in tokens, but breaks documented extensions using custom fields or childTokens. The tree walk can also change caller-supplied tokens, including throwing on frozen ones, so I haven't pushed that prototype. What normalization/raw boundary do you intend here, especially for the source passed to extension tokenizers? I want to settle that before broadening the change. Existing CR-to-LF normalization would stay unchanged. |
|
Ideally someone using marked lexer to parse markdown into tokens should be able to recreate the original markdown by appending raw from the top level block tokens, and recreate any token's markdown from is child tokens. We do remove CR for legacy reasons but eventually I would like to get rid of that as well. If someone uses extensions we cannot guarantee this anyways since all extension can set anything in raw. So this rule only applies to marked without any extensions. |
Keep custom tokenizer normalization compatible and avoid rewriting prior lexer results. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
|
Updated in 4f09817. Built-in tokenization now preserves literal NULs in Added raw-reconstruction tests and frozen prior-result coverage for inline tokens and repeated |
There was a problem hiding this comment.
use .md & .html files for these tests
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
|
Merged master into this branch (aeee4be) to resolve a conflict in |
Add the .md and .html fixture pair requested in review. The .md holds the literal NUL bytes. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
The web upload added a numeric prefix to the file name. It is re-added under the right name next. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Drop the numeric prefix the web upload added, so the .html matches its .md pair. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
The .md holds the literal NUL bytes, as in the earlier upload, under the right name. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Replaced by the md and html fixtures. Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
|
The .cjs spec is gone; the cases now live in test/specs/new/null_input_character.md and .html. One heads-up: the .md contains literal NUL bytes, so git and GitHub render it as binary and the diff is not readable inline. The cases are the same ones as before, with \0 for NUL; I can switch to a text-only .json fixture like the redos specs if you prefer. I kept test/unit/nullInput.test.js because it covers the raw-preservation behaviour from your earlier note; happy to fold that into fixtures too. |
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
|
Hi maintainers, I pushed an update that addresses the requested changes. When you have time, could you take another look? If anything else should change, please tell me and I'll fix it. Thanks for the reviews. hakarrr |
UziTech
left a comment
There was a problem hiding this comment.
Thanks for updating the PR — the raw preservation, .md/.html spec fixture format, recheck safety on all updated rules, and unit test coverage look solid.
Requesting a few changes to trim bundle size and avoid unnecessary hot-path overhead:
-
Bundle size (+1,334 B minified in
lib/marked.esm.js/lib/marked.umd.js, +384/+390 B gzipped)- TypeScript
privatefields (normalizeSourceNulls,inlineDepth,inlineHasNull) are not mangled by esbuild, so their full property names are repeated in the minified output. Switching to ECMAScript#privatefields or local variables/state and streamliningnormalizeTokenNulls/inlineTokensshould bring the minified growth well under 1 KB.
- TypeScript
-
Hot-path overhead & redundant work (
npm run benchmedian ~33% slower thancommonmarkvs30%onmaster)- In
src/Lexer.ts(inlineTokens), every call — including nested calls andinlineQueueruns insidelex()— runssrc.includes('\0')and tracksinlineDepth/inlineHasNulleven whenlex()already checkedhasNull === falsefor the whole input. - When
lex()does contain\0and!this.normalizeSourceNulls, queuedinlineTokens()calls normalize their tokens infinally, and thenlex()walks the entire token tree a second time vianormalizeTokenNulls(this.tokens.slice(firstToken)). - When
normalizeSourceNullsistrue,inlineTokens()runssrc.replace(other.nullCharacter, '\uFFFD')unconditionally even when!src.includes('\0')(and afterlex()already normalized the source). - In
src/helpers.ts(normalizeLabel), please gatelabel.replace(other.nullCharacter, '\uFFFD')withlabel.includes('\0')so NUL-free link labels skip the regex replace.
- In
-
Minor
null->undefinedcoercion onlink.title(src/Lexer.ts)link.title = link.title?.replace(other.nullCharacter, '\uFFFD')coercesnulltoundefined; guard withif (link.title)instead.
b0d5103 to
95a859a
Compare
Summary
Replace literal U+0000 input characters with U+FFFD in parsed output, as required by CommonMark section 2.3 and GFM section 2.3, while preserving built-in token
rawvalues. Existing carriage-return handling is unchanged.Built-in tokenization retains the source characters, treats NUL like U+FFFD in the affected delimiter and destination rules, and normalizes semantic token fields afterward. Extensions and custom tokenizer overrides retain pre-tokenization source normalization, preserving their custom fields and declared child tokens. Normalization only visits tokens and link objects owned by the current call, including when a Lexer is reused with frozen prior results.
This is input normalization, not HTML sanitization or a security vulnerability claim. It does not decode additional entities or add a dependency. Preprocess hooks still receive original input. A custom
provideLexerstill owns its source. Direct low-levelblockTokenscalls remain unchanged.Tests
npm test: 2,107 spec tests and 272 unit tests pass, plus docs/build, UMD/CJS, types and lint.References:
Demo comparison for
[x](/a\0b)(the URL contains%00; NUL is invisible in the input editor):Contributor
Committer