comark icon indicating copy to clipboard operation
comark copied to clipboard

Low version browsers such as Chrome 109 may generate errors when setting illegal attribute names

Open rock53770 opened this issue 4 months ago • 10 comments

Environment

Comark Version: 0.5.0 Framework: Vue Chrome Version: 109

Comark Version

v0.5.0

Reproduction

Chrome 109 Open the playground: https://comark.dev/play/editor?example=all-features Clear the editor and paste the markdown below

   :Alert{id="1""}

Description

The output of the large model is unstable and may output characters such as Alert {id="1""} with additional quotation marks, which can result in illegal attribute names and error messages in lower versions

Low version browsers such as Chrome 109 may generate errors when setting illegal attribute names

The 'is not a valid attribute name' in the error message refers to a single double quotation mark character. According to HTML standards, attribute names cannot contain characters such as', ',<,>,/,=, etc., so the browser directly throws a DOMException

Additional context

No response

Logs


rock53770 avatar Jul 15 '26 07:07 rock53770

function isValidAttrName(name) { try { document.createAttribute(name) return true } catch { return false } }

rock53770 avatar Jul 16 '26 06:07 rock53770

It can be modified through plugins. Please close it first

rock53770 avatar Jul 17 '26 09:07 rock53770

I've also encountered a similar issue — whether illegal attributes and other formats can be intercepted to prevent the engine from ‌freezing or crashing‌ during stream parsing due to non-compliant formats. thank you very much!

pony04311 avatar Jul 27 '26 02:07 pony04311

This should be fixed in https://github.com/comarkdown/comark/pull/298. I appreciate if you can verify the fix

farnabaz avatar Jul 28 '26 13:07 farnabaz

Issues may still arise when encountering dirty data. Is it possible to resolve the exceptions caused by dirty data?

pony04311 avatar Jul 29 '26 05:07 pony04311

This should be fixed in #298. I appreciate if you can verify the fix

function isValidAttrName(name) {
  try {
    document.createAttribute(name)
    return true
  } catch {
    return false
  }
}

Is it better to use this as each browser version supports different attributes?

rock53770 avatar Jul 29 '26 06:07 rock53770

@pony04311 What you mean by dirty data? H
ave you tried the PR release?

farnabaz avatar Jul 29 '26 08:07 farnabaz

Yes, I have used this PR code, but unfortunately it didn't resolve the issue I encountered. My goal is to ensure that no string stream input ever throws an error. If the content is not in Markdown format, output the original string. Thank you to the author—thank you so much, I really appreciate your hard work! Below is a summary of the cases I've personally compiled:

SAFE_ATTR_NAME_RE = /^:?[A-Za-z_][\w:.-]*$/

Attribute names that do not start with a letter or underscore (e.g., 123, -foo, .class) Names containing characters other than alphanumeric, underscores, colons, dots, or hyphens (e.g., @click, #id, café, paths, 🚀) Empty strings

PUNCT_POISON_RE = /[/\'"<>\s=,(){}[]|;]|:///

Contains / (e.g., path:/etc/passwd, foo/bar) Contains \ (e.g., C:\Users\x, \escaped) Contains ' or " (e.g., "id", 'title') Contains <> (e.g., a<b, a>b) Contains whitespace \s (e.g., foo bar, class) Contains = (e.g., a=b, onerror=alert(1)) Contains , (e.g., http://x/,) Contains ( ) { } [ ] (e.g., foo(bar), leftover {}, [link]) Contains | (e.g., a|b) Contains ; (e.g., foo;bar) Contains :// (e.g., http://evil.test, https://example.com)

Control characters + DEL (charCode <= 0x1f || charCode === 0x7f)

NUL \0 (e.g., \0hidden) SOH \x01 (e.g., a\x01b) Tab \t (e.g., \tclass) Newline \n (e.g., \nbreak) Carriage return \r (e.g., \rsuffix) DEL \x7f

C1 control characters (charCode >= 0x80 && charCode <= 0x9f)

Any character within these code points

Zero-width / bidirectional control characters / word joiners

ZWSP \u200b–\u200f (e.g., \u200bclass, class\u200b) Line separator / paragraph separator / LRO / RLO / PDF \u2028–\u202e (e.g., \u202ertl) Word joiner \u2060

Special Unicode characters

BOM \ufeff (e.g., \ufeffclass) Replacement character \ufffd (e.g., \ufffdpath) Surrogates (charCode >= 0xd800 && charCode <= 0xdfff, including emoji surrogate pairs)

Type and format checks in isValidAttrName (before regex)

name is null / undefined / not a string name.trim() !== name (leading or trailing whitespace)

DOM createAttribute validation (after passing regex)

Attribute names that pass the above rules but still throw an InvalidCharacterError in the browser (e.g., xmlns:foo/bar)

Structural validation failures (non-regex, during full traversal)

Proxy ownKeys throws an exception → unable to enumerate keys → marked as kind: "attrs-inspection-failed", original object retained Object is frozen/sealed and delete fails → reconstruct a prototype-free object AST element node is not writable (tryReplaceAttrs returns false) → repaired: false, surviving illegal keys logged

Diagnostic log classification (display only, not for interception)

Pattern matching in classifyBadAttrReason(): /:/// or /^https?:/i → "URL/protocol string" //\/ or /path\s*:/i or includes "{path" → "path fragment" /[{}]/ → "curly brace residue" /[@#$%^&*]/ → "special symbols" /[\s"'<>=,]/ → "spaces/quotes/angle brackets/equals" /[()[]|;]/ → "parentheses/vertical bar/semicolon" /[^\x20-\x7E]/ → "non-ASCII" !badAttr → "empty attribute name"

pony04311 avatar Jul 30 '26 02:07 pony04311

I believe what you are looking for is bit specific and not a general use. It would be great plugin for Comark. I'll update the PR to make sure attributes start with a-z chars but other non-markdown streaming is too much for Comark core.

If the content is not in Markdown format, output the original string.

This is also not possible imagine having <div 3attr="value">, it is not possible to keep 3attr="value" as text while it is an attribute

farnabaz avatar Jul 30 '26 15:07 farnabaz

ok thanks!

pony04311 avatar Aug 10 '26 01:08 pony04311