Recent

Author Topic: Incorrect implementation of TDOMElement.IsEmpty?  (Read 337 times)

dsiders

  • Full Member
  • ***
  • Posts: 213
Incorrect implementation of TDOMElement.IsEmpty?
« on: April 02, 2019, 12:59:27 am »
In unit components/lazutils/laz2_dom.pas.

TDOMElemen.IsEmpty seems to have an invalid implementation. The existing code checks for the presence of Attributes on the element.

The method is not part of the DOM specification. So I am assuming it is a convenience method.

And, according to the XML 1.0 specification, this implementation is not correct. XML defines an empty element as one with no content, as in child elements or text node, not Attributes. It explicitly allows attributes in an empty tag. See:

https://www.w3.org/TR/1998/REC-xml-19980210#sec-starttags

In other words, both of the following qualify as empty elements:

Code: XML  [Select]
  1. <foo/>
  2. <foo bar="42"/>
  3.  

Just looking for confirmation before submitting it as a bug...
« Last Edit: April 02, 2019, 01:10:49 am by dsiders »
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit

lucamar

  • Hero Member
  • *****
  • Posts: 1808
Re: Incorrect implementation of TDOMElement.IsEmpty?
« Reply #1 on: April 02, 2019, 01:10:22 am »
You're right, of course. According to the W3C specifications an empty element is one that has no content, but it can have attributes.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

dsiders

  • Full Member
  • ***
  • Posts: 213
Re: Incorrect implementation of TDOMElement.IsEmpty?
« Reply #2 on: April 02, 2019, 01:36:45 am »
You're right, of course. According to the W3C specifications an empty element is one that has no content, but it can have attributes.

Thanks @lucamar. I'll post to the bug tracker.
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit

dsiders

  • Full Member
  • ***
  • Posts: 213
Re: Incorrect implementation of TDOMElement.IsEmpty?
« Reply #3 on: April 02, 2019, 01:46:29 am »
In unit components/lazutils/laz2_dom.pas.

TDOMElemen.IsEmpty seems to have an invalid implementation. The existing code checks for the presence of Attributes on the element.

The method is not part of the DOM specification. So I am assuming it is a convenience method.

And, according to the XML 1.0 specification, this implementation is not correct. XML defines an empty element as one with no content, as in child elements or text node, not Attributes. It explicitly allows attributes in an empty tag. See:

https://www.w3.org/TR/1998/REC-xml-19980210#sec-starttags

In other words, both of the following qualify as empty elements:

Code: XML  [Select]
  1. <foo/>
  2. <foo bar="42"/>
  3.  

Just looking for confirmation before submitting it as a bug...

Submitted to bug tracker: https://bugs.freepascal.org/view.php?id=35308
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit