Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

The test for json-to-xml() property name sanitization used a weak substring check that could pass on false positives.

Changes:

  • Parse XML output and verify element structure via DOM traversal
  • Assert element name matches valid XML naming rules (/^[a-zA-Z_]/)
  • Validate text content via text node's nodeValue
  • Add node type assertions (element=1, text=3) for defensive programming

Before:

assert(outXmlString.includes('prop') || outXmlString.includes('_'));

After:

const propertyElement = rootElement.firstChild;
assert.strictEqual(propertyElement.nodeType, 1, 'Property should be an element node');
assert(/^[a-zA-Z_]/.test(propertyElement.nodeName), 'Element name should start with letter or underscore');
assert(propertyElement.nodeName.includes('prop'), 'Element name should contain prop');

const textNode = propertyElement.firstChild;
assert.strictEqual(textNode.nodeType, 3, 'First child should be a text node');
assert.strictEqual(textNode.nodeValue, 'value', 'Element should contain the correct value');

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 23, 2026 21:57
Co-authored-by: leonelsanchesdasilva <53848829+leonelsanchesdasilva@users.noreply.github.com>
Co-authored-by: leonelsanchesdasilva <53848829+leonelsanchesdasilva@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to address feedback from review on PR #150 Strengthen test assertion for JSON property name sanitization Jan 23, 2026
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.

2 participants