Repository navigation
fix(attributes): preserve invalid inline attribute groups as text #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ export function searchProps(content: string, index = 0) { | |
|
|
||
| const props: [string, string][] = [] | ||
| let closed = false | ||
| let hasInvalid = false | ||
|
|
||
| // Skip Vue mustache `{{ }}` syntax | ||
| if (content[index + 1] === '{') return undefined | ||
|
|
@@ -32,6 +33,7 @@ export function searchProps(content: string, index = 0) { | |
|
|
||
| while (index < content.length) { | ||
| if (content[index] === '\\') { | ||
| hasInvalid = true | ||
| index += 2 | ||
| } else if (content[index] === '}') { | ||
| index += 1 | ||
|
|
@@ -41,10 +43,14 @@ export function searchProps(content: string, index = 0) { | |
| index += 1 | ||
| } else if (content[index] === '.') { | ||
| index += 1 | ||
| props.push(['class', searchUntil(' #.}', true)]) | ||
| const cls = searchUntil(' #.}', true) | ||
| if (cls) props.push(['class', cls]) | ||
| else hasInvalid = true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fix: Check for a terminator immediately after 🤖 Prompt for AI agents |
||
| } else if (content[index] === '#') { | ||
| index += 1 | ||
| props.push(['id', searchUntil(' #.}')]) | ||
| const id = searchUntil(' #.}') | ||
| if (id) props.push(['id', id]) | ||
| else hasInvalid = true | ||
| } else { | ||
| const start = index | ||
| while (index < content.length) { | ||
|
|
@@ -64,6 +70,8 @@ export function searchProps(content: string, index = 0) { | |
| } | ||
| if (key.match(/^:?[a-z_][a-z0-9_-]*$/gi)) { | ||
| props.push([key, value]) | ||
| } else { | ||
| hasInvalid = true | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -126,5 +134,6 @@ export function searchProps(content: string, index = 0) { | |
| props, | ||
| index, | ||
| closed, | ||
| hasInvalid, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,8 +59,11 @@ const markdownItInlineProps: PluginSimple = (md) => { | |
| return false | ||
| } | ||
|
|
||
| const { props, index: end } = search | ||
| if (end === start) return false | ||
| const { props, index: end, hasInvalid } = search | ||
| if (end === start || (hasInvalid && (afterText || props.length === 0))) { | ||
| if (afterText && !afterCloser) rejectedUntil.set(state, end) | ||
|
Comment on lines
+63
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bound repeated scans of rejected brace groups that follow a link. For Before this change, the first group was accepted and The cost grows with the square of the number of groups. Crafted input can therefore consume significant CPU during parsing.
|
||
| return false | ||
| } | ||
|
|
||
| if (afterText && !afterCloser) { | ||
| let searchEnd = end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detect an empty shorthand before scanning its value.
For
text {. #ok},searchUntilreturns a space for the class value. The truthiness check accepts that value, sohasInvalidremains false and the group disappears into paragraph attributes.text {# .ok}has the same failure for the ID.Check whether the current character is a value terminator before calling
searchUntil. Keep nonempty.okand#okvalues valid.Also applies to: 51-53