diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-26 14:19:16 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-26 14:19:16 +1000 |
| commit | aecc0287efcb91105bfd4751fc5a4e1873348758 (patch) | |
| tree | 5d5d962bce08c66eb17b3900b61c3ffd0995bf2e /tests/rustdoc-ui | |
| parent | e011dd47ee04cd1e62786b5a0b3bfe2d5e58ae35 (diff) | |
| parent | d022089f58fa6bf8f4f0bb020640836eb10eae7a (diff) | |
| download | rust-aecc0287efcb91105bfd4751fc5a4e1873348758.tar.gz rust-aecc0287efcb91105bfd4751fc5a4e1873348758.zip | |
Rollup merge of #145535 - lolbinarycat:rustdoc-invalid_html_tags-svg-145529, r=GuillaumeGomez
make rustdoc::invalid_html_tags more robust best reviewed a commit at a time. I kept finding more edge case so I ended up having to make quite significant changes to the parser in order to make it preserve state across events and handle multiline attributes correctly. fixes rust-lang/rust#145529
Diffstat (limited to 'tests/rustdoc-ui')
| -rw-r--r-- | tests/rustdoc-ui/lints/invalid-html-tags.rs | 94 | ||||
| -rw-r--r-- | tests/rustdoc-ui/lints/invalid-html-tags.stderr | 71 |
2 files changed, 153 insertions, 12 deletions
diff --git a/tests/rustdoc-ui/lints/invalid-html-tags.rs b/tests/rustdoc-ui/lints/invalid-html-tags.rs index 317f1fd1d46..8003e5efdd5 100644 --- a/tests/rustdoc-ui/lints/invalid-html-tags.rs +++ b/tests/rustdoc-ui/lints/invalid-html-tags.rs @@ -43,7 +43,7 @@ pub fn b() {} /// <h3> //~^ ERROR unclosed HTML tag `h3` /// <script -//~^ ERROR unclosed HTML tag `script` +//~^ ERROR incomplete HTML tag `script` pub fn c() {} // Unclosed tags shouldn't warn if they are nested inside a <script> elem. @@ -72,6 +72,7 @@ pub fn e() {} /// <div></div > /// <div></div //~^ ERROR unclosed HTML tag `div` +//~| ERROR incomplete HTML tag `div` pub fn f() {} /// <!----> @@ -105,7 +106,7 @@ pub fn j() {} /// uiapp.run(&env::args().collect::<Vec<_>>()); /// ``` /// -/// <Vec<_> shouldn't warn! +// <Vec<_> shouldn't warn! /// `````` pub fn k() {} @@ -121,3 +122,92 @@ pub fn no_error_1() {} /// backslashed \<<a href=""> //~^ ERROR unclosed HTML tag `a` pub fn p() {} + +/// <svg width="512" height="512" viewBox="0 0 512" fill="none" xmlns="http://www.w3.org/2000/svg"> +/// <rect +/// width="256" +/// height="256" +/// fill="#5064C8" +/// stroke="black" +/// /> +/// </svg> +pub fn no_error_2() {} + +/// <div> +/// <img +/// src="https://example.com/ferris.png" +/// width="512" +/// height="512" +/// /> +/// </div> +pub fn no_error_3() {} + +/// > <div +/// > class="foo"> +/// > </div> +pub fn no_error_4() {} + +/// unfinished ALLOWED_UNCLOSED +/// +/// note: CommonMark doesn't allow an html block to start with a multiline tag, +/// so we use `<br>` a bunch to force these to be parsed as html blocks. +/// +/// <br> +/// <img +//~^ ERROR incomplete HTML tag `img` +pub fn q() {} + +/// nested unfinished ALLOWED_UNCLOSED +/// <p><img</p> +//~^ ERROR incomplete HTML tag `img` +pub fn r() {} + +/// > <br> +/// > <img +//~^ ERROR incomplete HTML tag `img` +/// > href="#broken" +pub fn s() {} + +/// <br> +/// <br<br> +//~^ ERROR incomplete HTML tag `br` +pub fn t() {} + +/// <br> +/// <br +//~^ ERROR incomplete HTML tag `br` +pub fn u() {} + +/// <a href=">" alt="<">html5 allows this</a> +pub fn no_error_5() {} + +/// <br> +/// <img title=" +/// html5 +/// allows +/// multiline +/// attr +/// values +/// these are just text, not tags: +/// </div> +/// <p/> +/// <div> +/// "> +pub fn no_error_6() {} + +/// <br> +/// <a href="data:text/html,<!DOCTYPE> +/// <html> +/// <body><b>this is allowed for some reason</b></body> +/// </html> +/// ">what</a> +pub fn no_error_7() {} + +/// Technically this is allowed per the html5 spec, +/// but there's basically no legitemate reason to do it, +/// so we don't allow it. +/// +/// <p <!-->foobar</p> +//~^ ERROR Unclosed HTML comment +//~| ERROR incomplete HTML tag `p` +pub fn v() {} diff --git a/tests/rustdoc-ui/lints/invalid-html-tags.stderr b/tests/rustdoc-ui/lints/invalid-html-tags.stderr index 9c2bfcf2c3d..b6ec22c2479 100644 --- a/tests/rustdoc-ui/lints/invalid-html-tags.stderr +++ b/tests/rustdoc-ui/lints/invalid-html-tags.stderr @@ -52,6 +52,12 @@ error: unclosed HTML tag `p` LL | /// <br/> <p> | ^^^ +error: incomplete HTML tag `script` + --> $DIR/invalid-html-tags.rs:45:5 + | +LL | /// <script + | ^^^^^^^ + error: unclosed HTML tag `div` --> $DIR/invalid-html-tags.rs:41:5 | @@ -64,11 +70,11 @@ error: unclosed HTML tag `h3` LL | /// <h3> | ^^^^ -error: unclosed HTML tag `script` - --> $DIR/invalid-html-tags.rs:45:5 +error: incomplete HTML tag `div` + --> $DIR/invalid-html-tags.rs:73:10 | -LL | /// <script - | ^^^^^^ +LL | /// <div></div + | ^^^^^ error: unclosed HTML tag `div` --> $DIR/invalid-html-tags.rs:73:5 @@ -77,28 +83,73 @@ LL | /// <div></div | ^^^^^ error: Unclosed HTML comment - --> $DIR/invalid-html-tags.rs:87:5 + --> $DIR/invalid-html-tags.rs:88:5 | LL | /// <!-- - | ^^^ + | ^^^^ error: unopened HTML tag `unopened-tag` - --> $DIR/invalid-html-tags.rs:114:26 + --> $DIR/invalid-html-tags.rs:115:26 | LL | /// Web Components style </unopened-tag> | ^^^^^^^^^^^^^^^ error: unclosed HTML tag `dashed-tags` - --> $DIR/invalid-html-tags.rs:112:26 + --> $DIR/invalid-html-tags.rs:113:26 | LL | /// Web Components style <dashed-tags> | ^^^^^^^^^^^^^ error: unclosed HTML tag `a` - --> $DIR/invalid-html-tags.rs:121:19 + --> $DIR/invalid-html-tags.rs:122:19 | LL | /// backslashed \<<a href=""> | ^^ -error: aborting due to 16 previous errors +error: incomplete HTML tag `img` + --> $DIR/invalid-html-tags.rs:156:5 + | +LL | /// <img + | ^^^^ + +error: incomplete HTML tag `img` + --> $DIR/invalid-html-tags.rs:161:8 + | +LL | /// <p><img</p> + | ^^^^ + +error: incomplete HTML tag `img` + --> $DIR/invalid-html-tags.rs:166:7 + | +LL | /// > <img + | _______^ +LL | | +LL | | /// > href="#broken" + | |____________________^ + +error: incomplete HTML tag `br` + --> $DIR/invalid-html-tags.rs:172:5 + | +LL | /// <br<br> + | ^^^ + +error: incomplete HTML tag `br` + --> $DIR/invalid-html-tags.rs:177:5 + | +LL | /// <br + | ^^^ + +error: incomplete HTML tag `p` + --> $DIR/invalid-html-tags.rs:210:5 + | +LL | /// <p <!-->foobar</p> + | ^^^ + +error: Unclosed HTML comment + --> $DIR/invalid-html-tags.rs:210:8 + | +LL | /// <p <!-->foobar</p> + | ^^^^ + +error: aborting due to 24 previous errors |
