Skip to content

Parser: Don't treat backslash as escape character in attribute values#1213

Merged
marcoroth merged 1 commit intomainfrom
fix-backslash-in-attribute-value
Feb 19, 2026
Merged

Parser: Don't treat backslash as escape character in attribute values#1213
marcoroth merged 1 commit intomainfrom
fix-backslash-in-attribute-value

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Feb 19, 2026

This pull request updates the parser to treat backslash as a literal character in HTML attribute values instead of an escape character.

The HTML spec does not define backslash as an escape character in attribute values. To include quote characters in attribute values, the spec recommends using HTML character references (e.g. " or ') or using a different quote style.

See: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

The following snippet:

<button data-shortcut="S,s,\">S \</button>

Now parses as:

@ DocumentNode (location: (1:0)-(1:42))
└── children: (3 items)
    ├── @ HTMLOpenTagNode (location: (1:0)-(1:30))
       ├── tag_opening: "<" (location: (1:0)-(1:1))
       ├── tag_name: "button" (location: (1:1)-(1:7))
       ├── tag_closing: ">" (location: (1:29)-(1:30))
       ├── children: (1 item)
          └── @ HTMLAttributeNode (location: (1:8)-(1:29))
              ├── name: 
                 └── @ HTMLAttributeNameNode (location: (1:8)-(1:21))
                     └── children: (1 item)
                         └── @ LiteralNode (location: (1:8)-(1:21))
                             └── content: "data-shortcut"
                             
              ├── equals: "=" (location: (1:21)-(1:22))
              └── value: 
                  └── @ HTMLAttributeValueNode (location: (1:22)-(1:29))
                      ├── open_quote: """ (location: (1:22)-(1:23))
                      ├── children: (1 item)
                         └── @ LiteralNode (location: (1:23)-(1:28))
                             └── content: "S,s,\\"
                         
                      ├── close_quote: """ (location: (1:28)-(1:29))
                      └── quoted: true
                      
       └── is_void: false
       
    ├── @ HTMLTextNode (location: (1:30)-(1:33))
       └── content: "S \\"
       
    └── @ HTMLCloseTagNode (location: (1:33)-(1:42))
        ├── tag_opening: "</" (location: (1:33)-(1:35))
        ├── tag_name: "button" (location: (1:35)-(1:41))
        └── tag_closing: ">" (location: (1:41)-(1:42))

Resolves #1211

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1213
npx https://pkg.pr.new/@herb-tools/language-server@1213
npx https://pkg.pr.new/@herb-tools/linter@1213

commit: 6519a74

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 6519a74


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit 5f21c2d into main Feb 19, 2026
32 checks passed
@marcoroth marcoroth deleted the fix-backslash-in-attribute-value branch February 19, 2026 22:38
@marcoroth marcoroth added this to the v1.0.0 milestone Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser: Error with backslash in attribute value

1 participant