Closed Bug 62269 Opened 24 years ago Closed 24 years ago

Interprets space/tab/newline as text

Categories

(Core :: DOM: Core & HTML, defect, P3)

x86
Linux
defect

Tracking

()

VERIFIED DUPLICATE of bug 26179

People

(Reporter: esigra, Assigned: jst)

Details

Hi,
Here is a testcase document that works as intended (try it):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html>
  <head>
    <title>
      Foo
    </title>
    <script type="text/javascript"><!--
      function toggle(caller) {
        target = caller.nextSibling
        //alert("\"" + target.getAttribute("style") + "\"")
        if (target.getAttribute("style") == "display: none; ") {
          target.setAttribute("style", "display: block; ")
        }
        else {target.setAttribute("style", "display: none; ")}
      }
    //--></script>
  </head>
  <body>
    <div onclick="toggle(this)">Bar</div><div>Fyr</div>
  </body>
</html>

The problem arises when I put space(s)/tab(s)/newline(s) between the divs. Then
Mozilla interprets it as a text node between the divs, which I believe is wrong.
(An extra .nextSibling will make it work again.)

As opposed to Mozilla, Konqueror's DOM implementation correctly ignores any
spaces/tabs/newlines between elements.
The DOM spec does not specify behavior for anonymous text nodes (what this white
space is).  For the <pre> element in HTML white space must be preserved.  HTML4
describes rendering of white space here:
http://www.w3.org/TR/html4/struct/text.html#whitespace

If this bug is valid it is probably a dup, I'm leaving it unconfirmed, but it is
probably invalid.
According to the example at
<http://www.webreference.com/js/column40/analyzesimple.html> (see also the tree
structure image linked from there), whitespace should not be interpreted as
nodes, so it sure looks like a Mozilla bug.
I think www.webreference.com is making some unwarranted assumptions.  The spec
does not prescribe what happens to the whitespace.  Furthermore, if we take
their example (which has a <p id="p2node">   </p> node) and apply the style
#p2node { white-space: pre } then suddenly the spaces need to be displayed and
there has to be a text node for those spaces.

Whether the node is created when the white-space:pre style is applied or when
the DOM tree is first created is not specified by the DOM spec and is an
implementation detail that you should not depend on.
You think of the whitespace <b>within</b> the p called p2node. I was more
concerned with the whitespace <b>between</b> the p nodes called p2node and
p3node. In this case it is a newline, and it could also include some kind of
indentation.

In this case, my common sense agrees with www.webreference.com's and Konqueror's
assumptions.
So what are we doing with this bug? I would like to get it off our Unconfirmed radar
Adding Master Spec to the CC list.
I am marking this NEW so someone with more knowledge of the specs then I do can
either fix this or mark this WONTFIX.
Status: UNCONFIRMED → NEW
Ever confirmed: true
This is a tricky one, mozilla and Mac IE preserves all whitespace and IE >5.0
and Konqueror looses whitespace between tags, so I'm not sure what the best
thing to do here is. Either way, this is a dup of bug 26179.

*** This bug has been marked as a duplicate of 26179 ***
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
Status: RESOLVED → VERIFIED
Component: DOM Level 1 → DOM Core
Component: DOM: Core → DOM: Core & HTML
QA Contact: jcarpenter0524 → general
You need to log in before you can comment on or make changes to this bug.