Recent

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

dsiders

  • Hero Member
  • *****
  • Posts: 1052
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 »
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
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.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

dsiders

  • Hero Member
  • *****
  • Posts: 1052
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
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018