Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,890 changes: 282 additions & 2,608 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions packages/parse5-parser-stream/test/parser-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ generateParsingTests(
'40.foreign-fragment',
'47.foreign-fragment',
'48.foreign-fragment',
// Select parsing was relaxed in the HTML spec.
// https://github.com/whatwg/html/pull/10548
// The forked test suite still tests the old behaviour.
'13.menuitem-element',
'29.tests1',
'101.tests1',
'3.tests10',
'4.tests10',
'16.tests10',
'17.tests10',
'4.tests9',
'5.tests9',
'17.tests9',
'18.tests9',
'13.tests18',
'14.tests18',
'17.webkit02',
'30.tests7',
'79.tests_innerHTML_1',
'80.tests_innerHTML_1',
'81.tests_innerHTML_1',
],
},
(test, opts) => parseChunked(test, opts),
Expand Down
4 changes: 4 additions & 0 deletions packages/parse5/lib/common/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ATTRS {
COLOR = 'color',
FACE = 'face',
SIZE = 'size',
SELECTED = 'selected',
}

/**
Expand Down Expand Up @@ -142,6 +143,7 @@ export enum TAG_NAMES {
SEARCH = 'search',
SECTION = 'section',
SELECT = 'select',
SELECTEDCONTENT = 'selectedcontent',
SOURCE = 'source',
SMALL = 'small',
SPAN = 'span',
Expand Down Expand Up @@ -296,6 +298,7 @@ export enum TAG_ID {
SEARCH,
SECTION,
SELECT,
SELECTEDCONTENT,
SOURCE,
SMALL,
SPAN,
Expand Down Expand Up @@ -428,6 +431,7 @@ const TAG_NAME_TO_ID = new Map<string, TAG_ID>([
[TAG_NAMES.SEARCH, TAG_ID.SEARCH],
[TAG_NAMES.SECTION, TAG_ID.SECTION],
[TAG_NAMES.SELECT, TAG_ID.SELECT],
[TAG_NAMES.SELECTEDCONTENT, TAG_ID.SELECTEDCONTENT],
[TAG_NAMES.SOURCE, TAG_ID.SOURCE],
[TAG_NAMES.SMALL, TAG_ID.SMALL],
[TAG_NAMES.SPAN, TAG_ID.SPAN],
Expand Down
68 changes: 68 additions & 0 deletions packages/parse5/lib/parser/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ generateParsingTests(
'40.foreign-fragment',
'47.foreign-fragment',
'48.foreign-fragment',
// Select parsing was relaxed in the HTML spec.
// https://github.com/whatwg/html/pull/10548
// The forked test suite still tests the old behaviour.
'13.menuitem-element',
'29.tests1',
'101.tests1',
'3.tests10',
'4.tests10',
'16.tests10',
'17.tests10',
'4.tests9',
'5.tests9',
'17.tests9',
'18.tests9',
'13.tests18',
'14.tests18',
'17.webkit02',
'30.tests7',
'79.tests_innerHTML_1',
'80.tests_innerHTML_1',
'81.tests_innerHTML_1',
],
},
(test, opts) => ({
Expand Down Expand Up @@ -151,4 +172,51 @@ describe('parser', () => {
expect((b.childNodes[0] as TextNode).value).toBe('should be outside');
});
});

describe('Customizable Select', () => {
it('should NOT enable selectedcontent for select multiple', () => {
const html = `
<select multiple>
<button>
<selectedcontent></selectedcontent>
</button>
<option selected>foo</option>
</select>
`;

const doc = parse(html);
const htmlEl = doc.childNodes.find((n) => n.nodeName === 'html') as Element;
const body = htmlEl.childNodes.find((n) => n.nodeName === 'body') as Element;
const select = body.childNodes.find((n) => (n as Element).tagName === 'select') as Element;
const button = select.childNodes.find((n) => (n as Element).tagName === 'button') as Element;
const selectedcontent = button.childNodes.find(
(n) => (n as Element).tagName === 'selectedcontent',
) as Element;

expect(selectedcontent.childNodes.length).toBe(0);
});

it('should enable selectedcontent for select without multiple', () => {
const html = `
<select>
<button>
<selectedcontent></selectedcontent>
</button>
<option selected>foo</option>
</select>
`;

const doc = parse(html);
const htmlEl = doc.childNodes.find((n) => n.nodeName === 'html') as Element;
const body = htmlEl.childNodes.find((n) => n.nodeName === 'body') as Element;
const select = body.childNodes.find((n) => (n as Element).tagName === 'select') as Element;
const button = select.childNodes.find((n) => (n as Element).tagName === 'button') as Element;
const selectedcontent = button.childNodes.find(
(n) => (n as Element).tagName === 'selectedcontent',
) as Element;

expect(selectedcontent.childNodes.length).toBeGreaterThan(0);
expect((selectedcontent.childNodes[0] as TextNode).value).toBe('foo');
});
});
});
Loading
Loading