fix(comark): treat colon followed by digits as plain text, not a component#234
Merged
Conversation
`:8100` is parsed as an inline component named `8100`, which makes
renderers call createElement('8100') and crash. A purely numeric name
should stay plain text. Added as a skipped SPEC repro (following the
existing leaf-block-directive.md precedent) so the suite stays green
until the inline-component parser rejects names that don't start with
a letter.
|
@antfubot is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
…onent
A component name must start with a letter or `$`, but the inline and block
parsers accepted digit-led names:
- inline `:8100` was captured as a component (`['8100', {}]`), making
renderers call `createElement('8100')` and crash the app;
- block `:8100` / `::8100` made `parseBlockParams` throw `Invalid block
params` during parsing.
Guard all three entry points with a shared `isComponentNameStart` helper that
mirrors the existing block name grammar (`RE_BLOCK_NAME = /^[a-z$]/i`), so a
colon sequence whose name doesn't start with a letter or `$` stays plain text.
Replaces the earlier skipped SPEC repro with a real regression test
(`test/component-name.test.ts`) covering inline and block cases plus
no-regression checks for valid components.
:8100)Replace the char-code `isComponentNameStart` with a regex-based `isValidComponentName` (`/^[a-z$][\w$-]*/i`) that mirrors the block name grammar. Behaviour is unchanged; the three guards now validate the candidate name string instead of a single leading char code.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
comark
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
❓ Type of change
📚 Description
A component name must start with a letter (or
$), but the parser accepted digit-led names, with two crash modes:Inline —
The server is running on :8100parsed:8100as a component:Renderers then call
createElement('8100')with a numeric tag name and crash the app.Block —
:8100(shorthand) and::8100(block) madeparseBlockParamsthrowInvalid block params: 8100during parsing.Root cause: the block name grammar already requires a letter/
$start (RE_BLOCK_NAME = /^[a-z$]/i), but the inline rule (/[\w$-]/) and the block pre-filters (/^:\w/, and the un-guarded::path) accepted digits.Fix: a shared
isComponentNameStarthelper guards all three entry points inpackages/comark/src/plugins/syntax.ts, mirroring the existing block grammar. A colon sequence whose name doesn't start with a letter or$now stays plain text instead of becoming a component or throwing.Behaviour after the fix:
… :8100(inline)['8100', {}]→createElement('8100')crash:8100:8100/::8100(block)Invalid block params:8100/::8100:inline-component,:badge[New],:h2,::alertNote: emoji shortcodes like
:100:are unaffected — the emoji rule runs earlier (before('emphasis')) than the inline component rule (after('entity')).Tests live in
packages/comark/test/component-name.test.ts(9 cases: inline + block regressions plus no-regression checks for valid components). They fail onmain(2 inline mismatches + 3 block throws) and pass with this change.📝 Checklist
pnpm verifyand it passes.This PR was created with the help of an agent.