Skip to content

fix: apply transformTagName once to self-closing tags - #881

Open
youdie006 wants to merge 1 commit into
NaturalIntelligence:masterfrom
youdie006:transform-tag-name-once
Open

youdie006 wants to merge 1 commit into
NaturalIntelligence:masterfrom
youdie006:transform-tag-name-once

Conversation

@youdie006

Copy link
Copy Markdown

Purpose / Goal

Self-closing tags go through transformTagName twice: once before the trailing / is stripped, so the callback receives e.g. a/, and again in the self-closing branch. Lowercase or map transforms hide it. With a non-idempotent one they don't:

new XMLParser({ transformTagName: n => 'ns_' + n }).parse('<root><a></a><a/></root>')
// actual:   {"ns_root":{"ns_a":"","ns_ns_a":""}}
// expected: {"ns_root":{"ns_a":["",""]}}

This strips the / before the single transform call and removes the second call, so each tag is transformed once with its real name. Two side effects of the move:

  • strictReservedNames now also rejects <#text/>. Before, it produced {"r":[]}, while <#text></#text> and <#text a="1"/> already threw.
  • With a non-idempotent transform and allowBooleanAttributes, <a a/> no longer keeps @_a. It only had it because the doubled name made tagName !== tagExp; without a transform it is already dropped. That is a separate bug in the attribute check, not touched here.

Added a spec covering paired, empty and attributed self-closing tags. npm test passes (333 specs) on Node 22 and 14.

Type

  • Bug Fix
  • Refactoring / Technology upgrade
  • New Feature

Written with AI assistance (Claude); I have reviewed the change.

The opening-tag path transformed the name before the trailing / was
stripped, so the callback got e.g. 'item/', and the self-closing branch
transformed it again. Strip the / first and drop the second call.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant