HTML spec compliance: `li` and `p` tags are parsed incorrectly

This issue has been created since 2022-09-18.

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

const { parseTemplate } = require("@angular/compiler");
const ast = parseTemplate("<ul><li>bbb<p>ccc<li>ddd</ul>");
console.log(ast.nodes[0].children.length); // Actual: 1. Expected: 2

The second li tag should close the first li. Instead of that, it's parsed as a child of the p element.

Please provide a link to a minimal reproduction of the bug

https://codesandbox.io/s/flamboyant-lalande-8kpny2?file=/src/index.js

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular 14.2.2

Anything else?

No response

JoostK wrote this answer on 2022-09-19

Almost all HTML parsers on https://astexplorer.net get this incorrect, except for parse5. I wouldn't trust on this working as the HTML spec prescribes if I were you ;)

I have a fix in #47474 (nice issue number) but labeled it as risky, as it's hard to predict what the exact impact of this change is.

thorn0 wrote this answer on 2022-09-19

No need to trust those parsers (overall, IMHO, it's a bad idea to use them as a reference). Check the spec:

An li element's end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.

A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.

Or check how any browser parses this. li can't be a child of p.

JoostK wrote this answer on 2022-09-19

No need to trust those parsers

I wasn't suggesting I did; I mentioned it to indicate that this is widely parsed incorrectly.

thorn0 wrote this answer on 2022-09-19

Yeah. Perhaps, because the spec could be more clear on this.

thorn0 wrote this answer on 2022-09-19

A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element

li isn't explicitly mentioned in this list for the same reason tr and td aren't.

thorn0 wrote this answer on 2022-09-19

Turns out td is parsed incorrectly as well:

const { parseTemplate } = require("@angular/compiler");
const ast = parseTemplate("<table><tr><td>bbb<p>ccc<td>ddd</table>");
console.log(ast.nodes[0].children[0].children.length); // Actual: 1. Expected: 2

https://codesandbox.io/s/great-sammet-hr0k6i?file=/src/index.js

thorn0 wrote this answer on 2022-09-19

Same with <table><tr><td>bbb<li>ccc<td>ddd</table>

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-10-04
Star Count 84139
Watcher Count 3064
Fork Count 22243
Issue Count 1206

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Implement additional properties transfer from Allure report to AzureDevOps Test Runs 0 2022-07-21 2022-07-22
Dependency Dashboard 0 2021-10-18 2022-08-03
🆕 Software Suggestion | Guardedbox 3 2021-08-30 2022-07-31
Structured bindings for member pointers 4 2021-07-20 2022-10-04
Library not updated? 1 2021-09-07 2022-08-16
.TweetMode == TweetMode.Extended no longer works. :( 5 2021-11-07 2022-06-28
Suggestion - timeout for scrapoing 2 2021-04-16 2022-10-02
New "Maps" feature in screener view is messing up the columns that are pulled when using finviz screener 2 2022-03-29 2022-09-01
Communication with the programmer 1 2021-06-13 2022-06-27
Please add a TbSync icon to the Thunderbird Spaces Toolbar 1 2022-09-16 2022-09-16
Missing device configuration: Fakro AMZ Solar / Device ID 0x0085-0x0005-0x0012 2 2022-09-09 2022-09-27
S2: When a node does not understand an outgoing SupervisionReport, chaos ensues 0 2022-09-08 2022-09-27
Elixir 1.8 compatibility 1 2019-01-24 2022-07-23
Android: Widget seems to not load in v12.0 0 2022-09-04 2022-10-04
Add Arduino Pro Portenta X8 to your supported board list 0 2022-07-20 2022-07-17
Remove mutable objects from analyze arguments. 1 2021-09-22 2022-07-07
input 后缀为选择框无法选值 1 2021-05-07 2022-01-19
URI with Query Params fails to match 4 2021-02-02 2022-09-02
Handle ppoll, pselect, epoll_pwait atomicity for race conditions 1 2018-10-25 2022-10-01
How to deploy individual saleor modue(storefront,dashboard,saleor [3.1]) with docker-compose?? 0 2021-11-03 2021-10-31
Can anyone help me with Documentation for Kubernates K8s Deployment on Digital Ocean!!! 0 2021-11-03 2022-09-06
Ubuntu22.04 - PHP muliple deprecated library vendor/corneltek warning 1 2022-06-10 2022-09-08
RBAC Permissions for Developers/Users 4 2020-05-10 2021-10-23
OpenAPI documentation 2 2020-04-18 2021-10-29
Pull Sonarr commit 'Fixed: PRevent import if potential bulk season release doesn't have air date for all episodes' 0 2022-05-23 2022-07-24
Library Cache 0 2015-07-01 2022-01-23
Redesign Gossip Topology 0 2022-03-15 2022-09-20
Bug: when port is 0,will cause connection be override 0 2021-10-21 2022-09-20
High availability control plane 3 2022-01-26 2022-08-31
Export CMake targets 5 2020-08-18 2022-10-02
Loading symbol as toplevel worker is loaded 19 2021-10-12 2022-09-13
Cell edits don't reflect across duplicate widget instances 0 2021-03-05 2022-09-10
-L option accepts target argument, but target is already a positional argument 1 2021-10-01 2022-09-12
[BUG] example里面的图片如png是不是有问题? 1 2021-11-02 2022-09-17
LoggerWriterConsole is only defined in [email protected] 0 2021-08-07 2022-09-02
OpenCV from 4.5.4 to 4.5.5 SegFault in cv2.connectedComponentsWithStats 7 2021-12-29 2022-09-13
slow_pwm - Output glitches off after several hours of running 1 2022-06-22 2022-09-16
[prim_secded_inv_hamming_39_32] Error detection 2 2022-04-01 2022-06-30
Object of class Illuminate\Translation\FileLoader could not be converted to string 1 2021-09-23 2022-09-26
Error message for non-spec-compliant links 1 2020-12-15 2022-09-26
Error when unit testing 0 2022-06-22 2022-09-26
Restore lost ability to rotate the navigation + physics layers of tilemaps 7 2022-07-22 2022-09-27
Make the `--export` output path relative to the current working directory instead of the project root 0 2022-07-22 2022-09-16
Feature: Remove FullTrust handlers 5 2022-08-30 2022-09-02
Agenda for June 23, 2022 OMR Architecture Meeting 0 2022-05-25 2022-10-03
MQTT server sample code 0 2021-08-13 2022-09-09
Issues with Service Bus Sdk 31 2021-11-17 2022-10-02
Error when attempting to retrieve ProjectReport with JobcodeId. 2 2021-07-29 2022-08-05
has Groovy 2.5 compiler support been dropped in the latest version? 1 2021-07-27 2022-08-19
Add sensor and behavior tick rate doc 0 2021-07-20 2022-09-22