Skip to content

Fix support for empty attributes #6

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

Merged
merged 3 commits into from
Mar 10, 2023
Merged

Conversation

tmelliottjr
Copy link
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

This change adds handling for attributes that are explicitly set with an empty string "" or all whitespace " ".

Prior to this, html comments that contained an empty string attribute were ignored completely.

For example, given the following html commentMarker returns null.

const html = '<!-- action target="1234" field="type" value="" -->'
const marker = commentMarker(node)
// marker === null

Additionally, attributes with whitespace only were coerced to number resulting in unexpected behavior.

For example, the following results in an attribute value of 0.

const html = '<!-- action target="1234" field="type" value=" " -->'
const marker = commentMarker(node)
// marker.parameters === {
//   target: 1234,
//   field: "type",
//   value: 0,
// }

@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 Mar 10, 2023
@tmelliottjr tmelliottjr changed the title handle empty attributes, tests handle empty attributes Mar 10, 2023
Signed-off-by: Titus <[email protected]>
Co-authored-by: Titus <[email protected]>
Signed-off-by: Tom Elliott <[email protected]>
@wooorm wooorm changed the title handle empty attributes Fix support for empty attributes Mar 10, 2023
@wooorm wooorm merged commit 9639c39 into syntax-tree:main Mar 10, 2023
@github-actions

This comment has been minimized.

@wooorm
Copy link
Member

wooorm commented Mar 10, 2023

Thanks, released in 2.1.2!!

@wooorm wooorm added 🐛 type/bug This is a problem 💪 phase/solved Post is done labels Mar 10, 2023
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Mar 10, 2023
@mikesurowiec
Copy link

@wooorm @tmelliottjr thank you both for this! 👏

@tmelliottjr
Copy link
Contributor Author

Thank you for the quick 👀 on this, greatly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

3 participants