Skip to content

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

Closed

Description

@rock53770

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

Activity

  1. added
    bug
    on Jul 15, 2026
  2. rock53770 commented on Jul 16, 2026

    @rock53770
    Author

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

  3. rock53770 commented on Jul 17, 2026

    @rock53770
    Author

    It can be modified through plugins. Please close it first

  4. pony04311 commented on Jul 27, 2026

    @pony04311

    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!

  5. farnabaz commented on Jul 28, 2026

    @farnabaz
    Collaborator

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

  6. pony04311 commented on Jul 29, 2026

    @pony04311

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

  7. rock53770 commented on Jul 29, 2026

    @rock53770
    Author

    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?

  8. farnabaz commented on Jul 29, 2026

    @farnabaz
    Collaborator

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

  9. pony04311 commented on Jul 30, 2026

    @pony04311

    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"

  10. farnabaz commented on Jul 30, 2026

    @farnabaz
    Collaborator

    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

  11. pony04311 commented on Aug 10, 2026

    @pony04311

    ok thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions