Skip to content

Commit

Permalink
fix: resolving tags without attribute values causes confusion (#485)
Browse files Browse the repository at this point in the history
Closes #486

---------

Co-authored-by: chengcp <ccp06939@itsmycar.cn>
Co-authored-by: Christian Bewernitz <coder@karfau.de>
  • Loading branch information
3 people committed Mar 31, 2023
1 parent 38c7da5 commit 5c671dc
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/sax.js
Expand Up @@ -313,7 +313,9 @@ function parseElementStartPart(source, start, el, currentNSMap, entityReplacer,
el.closed = true;
case S_ATTR_NOQUOT_VALUE:
case S_ATTR:
break;
case S_ATTR_SPACE:
el.closed = true;
break;
//case S_EQ:
default:
Expand Down
18 changes: 18 additions & 0 deletions test/parse/__snapshots__/parse-element.test.js.snap
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`XML Node Parse closing tag with unquoted value ending with // 1`] = `
Object {
"warning": Array [
"[xmldom warning] attribute \\"lazy/\\" missed quot(\\")!
@#[line:3,col:3]",
],
}
`;

exports[`XML Node Parse closing tag with unquoted value including / followed by space / 1`] = `
Object {
"warning": Array [
"[xmldom warning] attribute \\"lazy/\\" missed quot(\\")!!
@#[line:3,col:3]",
],
}
`;

exports[`XML Node Parse namespaced attributes unclosed root tag will be closed 1`] = `
Object {
"actual": "<xml xmlns=\\"1\\" xmlns:a=\\"2\\" a:test=\\"3/\\"/>",
Expand Down
111 changes: 111 additions & 0 deletions test/parse/parse-element.test.js
Expand Up @@ -39,6 +39,117 @@ describe('XML Node Parse', () => {
expect(actual).toBe(`<xml><book/><title>Harry Potter</title></xml>`);
});

it('closing tag without attribute value', () => {
const actual = new DOMParser()
.parseFromString(
`<template>
<view>
<image lazy />
<image></image>
</view>
</template>`,
'text/xml'
)
.toString();
expect(actual).toBe(
`<template>
<view>
<image lazy="lazy"/>
<image/>
</view>
</template>`
);
});
it('closing tag with unquoted value following /', () => {
const actual = new DOMParser()
.parseFromString(
`<template>
<view>
<image lazy=lazy/>
<image></image>
</view>
</template>`,
'text/xml'
)
.toString();
expect(actual).toBe(
`<template>
<view>
<image lazy="lazy"/>
<image/>
</view>
</template>`
);
});
it('closing tag with unquoted value following space and /', () => {
const actual = new DOMParser()
.parseFromString(
`<template>
<view>
<image lazy=lazy />
<image></image>
</view>
</template>`,
'text/xml'
)
.toString();
expect(actual).toBe(
`<template>
<view>
<image lazy="lazy"/>
<image/>
</view>
</template>`
);
});
it('closing tag with unquoted value including / followed by space /', () => {
const { errors, parser } = getTestParser();
const actual = parser
.parseFromString(
`<template>
<view>
<image lazy=lazy/ />
<image></image>
</view>
</template>`,
'text/xml'
)
.toString();
expect(errors).toMatchSnapshot();
expect(actual).toBe(
`<template>
<view>
<image lazy="lazy/"/>
<image/>
</view>
</template>`
);
});
it('closing tag with unquoted value ending with //', () => {
const { errors, parser } = getTestParser();

const actual = parser
.parseFromString(
`<template>
<view>
<image lazy=lazy//>
<image></image>
</view>
</template>`,
'text/xml'
)
.toString();
expect(errors).toMatchSnapshot();
expect(actual).toBe(
`<template>
<view>
<image lazy="lazy/"/>
<image/>
</view>
</template>`
);
});

describe('simple attributes', () => {
describe('nothing special', () => {
it.each(['<xml a="1" b="2"></xml>', '<xml a="1" b="2" ></xml>', '<xml a="1" b="2" />'])('%s', (input) => {
Expand Down

0 comments on commit 5c671dc

Please sign in to comment.