Skip to content

Commit

Permalink
test: add cases related to unquoted attr values and slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
karfau committed Mar 31, 2023
1 parent b3fcf17 commit 61f1a3f
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
27 changes: 27 additions & 0 deletions test/parse/__snapshots__/parse-element.test.js.snap
@@ -1,5 +1,32 @@
// 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 closing tag with unquoted value including / followed by space / 2`] = `
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
92 changes: 90 additions & 2 deletions test/parse/parse-element.test.js
Expand Up @@ -39,7 +39,7 @@ describe('XML Node Parse', () => {
expect(actual).toBe(`<xml><book/><title>Harry Potter</title></xml>`);
});

it('without attribute values', () => {
it('closing tag without attribute value', () => {
const actual = new DOMParser()
.parseFromString(
`<template>
Expand All @@ -51,7 +51,6 @@ describe('XML Node Parse', () => {
'text/xml'
)
.toString();
console.log(actual);
expect(actual).toBe(
`<template>
<view>
Expand All @@ -61,6 +60,95 @@ describe('XML Node Parse', () => {
</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', () => {
Expand Down

0 comments on commit 61f1a3f

Please sign in to comment.