Skip to content
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

type="anything" is parsed as child instead of property #8

Closed
4 tasks done
albinekb opened this issue Nov 18, 2024 · 4 comments · Fixed by syntax-tree/hast-util-from-parse5#14
Closed
4 tasks done
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@albinekb
Copy link

albinekb commented Nov 18, 2024

Initial checklist

Affected packages and versions

hast-util-from-html@2.0.3

Link to runnable example

https://github.com/albinekb/hast-unknown-node-repro/blob/main/index.ts

Steps to reproduce

import { fromHtml } from 'hast-util-from-html'
const tree = fromHtml('<button type="login">Hello</button>', { fragment: true })

Expected behavior

Parses like any other property:

{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'button',
      properties: { type: 'login' },
      children: [
        {
          type: 'text',
          value: 'Hello',
          position: {
            start: { line: 1, column: 23, offset: 22 },
            end: { line: 1, column: 28, offset: 27 }
          }
        }
      ],
      position: {
        start: { line: 1, column: 1, offset: 0 },
        end: { line: 1, column: 37, offset: 36 }
      }
    }
  ],
  data: { quirksMode: false },
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 1, column: 37, offset: 36 }
  }
}

Actual behavior

Putting anything else than "submit", "reset", "button" in type="", moves the property from the properties to being a child:

{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'button',
      properties: {},
      children: [
        { type: 'login' }, // <=== Should not be here?
        {
          type: 'text',
          value: 'Hello',
          position: {
            start: { line: 1, column: 22, offset: 21 },
            end: { line: 1, column: 27, offset: 26 }
          }
        }
      ],
      position: {
        start: { line: 1, column: 1, offset: 0 },
        end: { line: 1, column: 36, offset: 35 }
      }
    }
  ],
  data: { quirksMode: false },
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 1, column: 36, offset: 35 }
  }
}

If i put more attributes on the button:

fromHtml('<button aria-type="button" type="broken" disabled>Hello</button>', { fragment: true })

The other attributes gets added to the erroneous child:


    {
      type: 'element',
      tagName: 'button',
      properties: {},
      children: [
        { 'aria-type': 'button', type: 'broken', disabled: '' },
        {
          type: 'text',
          value: 'Hello',
          position: {
            start: { line: 1, column: 50, offset: 49 },
            end: { line: 1, column: 55, offset: 54 }
          }
        } 
      ]

Affected runtime and version

node@20.12.2

Affected package manager and version

pnpm@9.13.2

Affected OS and version

No response

Build and bundle tools

esbuild

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Nov 18, 2024
@albinekb
Copy link
Author

albinekb commented Nov 18, 2024

Update, after more investigation, it looks like I filed this under the wrong package again:

syntax-tree/hast-util-from-parse5@main...albinekb:hast-util-from-parse5:unknown-attribute-test

hast-util-from-parse5 seems to be the source of the error..

Update:

Found the line:https://github.com/syntax-tree/hastscript/blob/2a7451dc1eb2adc6b07af6efed8a8bdcc8f13758/lib/create-h.js#L166

Seems to be fixed in hastscript 9.0.0? syntax-tree/hastscript@8a5f97e

wooorm pushed a commit to syntax-tree/hast-util-from-parse5 that referenced this issue Nov 19, 2024
Closes GH-14.
Closes syntax-tree/hast-util-from-html#8

Reviewed-by: Titus Wormer <tituswormer@gmail.com>

This comment has been minimized.

@wooorm wooorm added the 👀 no/external This makes more sense somewhere else label Nov 19, 2024

This comment was marked as resolved.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Nov 19, 2024
@wooorm
Copy link
Member

wooorm commented Nov 19, 2024

Released in hast-util-from-parse5@8.0.2, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

Successfully merging a pull request may close this issue.

2 participants