question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SelfClosing Tags have incorrect html, generated unclosed tags.

See original GitHub issue

Bug Report

Prerequisites

  • [/] Can you reproduce the problem in a MWE?
  • [/] Are you running the latest version of AngleSharp?
  • [/] Did you check the FAQs to see if that helps you?
  • [/] Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
  • [/] Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Description

Given a self-closing tag such as <input type='text' />, doing a ToHtml() on it, or using the OuterHtml property both return an unclosed tag.

Steps to Reproduce

var config = Configuration.Default;
var context= BrowsingContext.New(config);
var source = "<input type='text' />";
var document = await context.OpenAsync(req => req.Content(source));
var input = document.QuerySelector("input");
input.OuterHtml.Dump();
input.ToHtml().Dump();

Expected behavior: returns <input type='text' />

Actual behavior: returns <input type='text'>

Environment details: Windows, .NET 6.0.14

Possible Solution

https://github.com/AngleSharp/AngleSharp/blob/3a21e4c65b53dbd53d35dee4b1f692659a7f535e/src/AngleSharp/Html/HtmlMarkupFormatter.cs#L69

I believe the above line needs to have a code path that adds /> when selfClosing is true.

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
FlorianRapplcommented, Mar 22, 2023

We also have an XHTML formatter - so the parsed DOM could be represented in XHTML (here, we place the solidus; see https://github.com/AngleSharp/AngleSharp/blob/devel/src/AngleSharp/Xhtml/XhtmlMarkupFormatter.cs#L103).

0reactions
jbrayfaithlifecommented, Mar 22, 2023

Learn something new every day. For anyone’s future reference, this came out of a project where we are manipulating XHTML. Apparently I misunderstood the relationship between the various specs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Self-closing tag syntax error in HTML documents
Using the W3c.org HTML validator, today I started receiving a new error indicating an issue with all self-closing HTML tags. The error is:....
Read more >
Escaping input with unclosed, invalid tags returns it ...
To Reproduce From the Node REPL: > const s = require('sanitize-html') undefined > s("here's a string with a tag.
Read more >
The case against self-closing tags in HTML
A major part of the problem is that /> is sometimes ignored, and sometimes not, within the same HTML document. Could we have...
Read more >
What are Self Closing Tags in HTML?
Self -closing tags in HTML are sometimes also known as empty tags, void tags, singletons tags, etc. This means that these tags have...
Read more >
The case against self-closing tags in HTML
Self -closing tags are an inconsequential issue. Of actual practical consequence are optional html5 tags [0]. They allow you to write html by ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found