Closed Bug 129508 Opened 24 years ago Closed 21 years ago

Save As turns <p><table></table> into invalid <p><table></table></p>

Categories

(Core :: DOM: Serializers, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: cjmorland, Assigned: t_mutreja)

References

()

Details

(Whiteboard: [needs review])

Attachments

(3 files, 1 obsolete file)

From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020214 BuildID: 20020214 If you validate this page, it is legal. If you do "save as", the upload to the validator, it will not verify. Reproducible: Always Steps to Reproduce: 1.validate the page (validator.w3.org) 2."save as" the page. 3.upload the page to the validator. 4.redo 1-3, using lynx. Expected Results: Don't break working HTML!
Severity: enhancement → normal
OS: Linux → All
Attached file Original HTML Source —
To DOM-to-text conversion. The parser allows <table> inside <p>, which the W3C validator apparently does not. The source has: <p><table></table> So we output: <p><table></table></p> and the validator treats this as: <p></p><table></table></p> and barfs. This all happens only when saving "web page, complete". And HTML-only save works fine.
Assignee: law → harishd
Severity: normal → enhancement
Status: UNCONFIRMED → NEW
Component: File Handling → DOM to Text Conversion
Ever confirmed: true
OS: All → Linux
QA Contact: sairuh → sujay
Boris, I hope that your Nor -> Enh and All -> Linux was only for later loaded form. Setting back (as my Win build does it too).
Severity: enhancement → normal
OS: Linux → All
--> Tanu
Assignee: harishd → tmutreja
Status: NEW → ASSIGNED
Attached patch Patch V1.0 (obsolete) — — Splinter Review
Though comment in the code says 'table' to be required for fixing bug #43678, I could not reproduce bug#43678 even after removing 'table' but as I don't have much knowledge about this part of the code, I'm unable to see the actual side effects, if any. In case this is the wrong place to fix this bug, following diff can provide the alternate solution: Index: CNavDTD.cpp =================================================================== RCS file: /cvsroot/mozilla/htmlparser/src/CNavDTD.cpp,v retrieving revision 3.383 diff -r3.383 CNavDTD.cpp 2522a2523,2526 > if((eHTMLTag_table==aChild || eHTMLTag_tbody==aChild || eHTMLTag_tr==aChild || > eHTMLTag_th==aChild) && (eHTMLTag_p==aParent)) { > result=PR_FALSE; > } Harish, I need your inputs here.
Keywords: patch
Whiteboard: [needs review]
Tanu: P is allowed to contain a TABLE for backwards compatibility, even though it violates the spec., so please don't remove that. It will break a lot of sites. I don't understand your second diff. Could you explain that? FYI: IMO, this problem is not easy to fix ( I may be wrong ) and fixing it in CNavDTD is a bit dangerous ( it would change existing behavior ).
>P is allowed to contain a TABLE for backwards compatibility, even though >it violates the spec. Then this bug should be a "WONTFIX" one. My second solution is also based on the fact that P can NOT contain TABLE. Harish, you may like check the second diff to see the impact. The Unified diff is as following: RCS file: /cvsroot/mozilla/htmlparser/src/CNavDTD.cpp,v retrieving revision 3.383 diff -u -r3.383 CNavDTD.cpp --- CNavDTD.cpp 11 Apr 2002 23:50:39 -0000 3.383 +++ CNavDTD.cpp 20 Apr 2002 10:51:16 -0000 @@ -2520,6 +2520,10 @@ } } } + if((eHTMLTag_table==aChild || eHTMLTag_tbody==aChild || eHTMLTag_tr==aChild || + eHTMLTag_th==aChild) && (eHTMLTag_p==aParent)) { + result=PR_FALSE; + } return result; }
Tanu: Why do you think the fix should be in CNavDTD? IMO, this should be fixed in the plaintext serializer.
Harish, my observation here was the same as comment#2, based on which I feel that any such constraint should be part of the DTD. Fixing this in serializer does not look good in the sense that the input DOM tree provided to serializer is already allowing <table> to be present inside <p> and I feel during serialization, we should not change the DOM at all.
>Harish, my observation here was the same as comment#2, based on which I feel >that any such constraint should be part of the DTD. Unfortunately, you cannot fix the DTD because it will break compatibilty. However, we don't have that constraint in the plain text serializer and we're free to correct the markup ( I think :-/ ). AFAIK, you can always add a rule, in the plain text serializer, to close out P before opening up TABLE.
Attachment #79255 - Attachment is obsolete: true
CC'ing Akkana and Jfrancis for review & comments.
Um, since the fix seems to be in the document encoder, I think you need to make sure that it does not break XML serialization. What if I have arbitrary XML, no namespaces or anything, like this: "<doc><p><table/></p></doc>"? I would suggest that you try to push the fix to the serializers where there is no harm. Or if it makes sense to have it in the document encoder, make sure that it only applies to HTML and XHTML.
I'm trying to fix it in nsHTMLContentSerializer but the preblem I'm facing is with FixupNode() in nsDocumentEncoder.cpp (near line# 297): if (mNodeFixup) { mNodeFixup->FixupNode(aNode, getter_AddRefs(node)); } if (!node) { node = do_QueryInterface(aNode); } FixupNode is doing only a shallow copy and hence the node losses it's link with the parent node. Is this shallow copy a requirement or it can be changed to retain the link with the parent?
The shallow copy gives us performance, we really should try not to change that. I don't have any good suggestions at this time... :/
Fixing this seems like a lot of pain with little gain. We should emit the doc the DOM gives us. If it's illegal, that's the fault of the parser (or of the editor if the dom has been editted). I can't see how it's the serializers job to fix that. As an example, what if there were more text after the table, and we have text coloration style on the paragraph? In mozilla that text will be colored, since we forgive the table inside the p. But after a save and reload, that text would not be colored. GIVEN that we allow illegal html to start with, that html should round-trip through the serializer without degradation. If someone wants valid markup, they can close their bloomin' p tags. my 2¢
I agree it's much work for no significant gain and it's definitely not the serializer's job but mozilla promises the standards. Had it been just a point to render an illegal/incomplete HTML it was worth ignorance but the problem here is that "a legal HTML page is getting saved as an illegal one" by mozilla.
We are going to need more differentiation here. If folks are save a page, they will expect further viewings of the saved page to look the same. This proposed fix will break that. I don't see why it's a problem to save "quirks" html. That's the only kind we view. If we had a strict viewing mode, then I would expect that to save as strict html. But the two need to match. How can it be non-compliant to save "illegal" html, but be compliant to treat legal html as if it were quirky?
Fix is meaningful and required only in 'Save As' with 'Web page, complete' cases. In that case even if the saved HTML page looks different, it should be fine as they are different in content itself.
If I'm understanding this bug, people are worried about the saved html being illegal, but nobody seems to be worried about the fact that the dom tree is also illegal. Isn't that a problem? Might that not cause problems for code which accesses the dom and expect it to conform to the spec? Doesn't putting a band-aid on the output system just hide the real problem, begging for it to come back and bite us later?
Akanna, I do agree with what you wrote and that's the reason I first tried fixing it in DTD part itself but comment# 11 restricts that fix for backward compatibility. Probably band-aid patch would just mean that existing HTML sources that contain <table> inside <p> would appear based on the earlier standards and if at all mozilla happens to save that page, it will save with latest standards.
Some commentary on IRC tonight on how to solve the general case of these problems: Suggestion was to save additional information in the DOM for each element node. Amount of data storage could range from storing full text of start-tag and end-tag with the node, to a more compressed version, i.e., end-tag could have 3 values, full (</generic identifier>), short (</>), or none (). Also a bit or two to preserve the linefeeds discussed in bug 2750. Suggestion that maybe we only add the augmentations to the DOM when creating it for editor; I know the parser flag for view-source could probably be adapted to have an additional value signaling a parse by the editor, but I don't know what would have to happen downstream in content sink and beyond.
I'd rather not add overhead just to allow html that is valid but not interpreted as valid to pass through Mozilla unchanged. The html and dom tree are bogus, and Mozilla should be honest about that. Can we remove the quirk that allows paragraphs to contain tables from standards mode?
Summary: Save As turns legal HTML into illegal HTML → Save As turns <p><table></table> into invalid <p><table></table></p>
*** Bug 206291 has been marked as a duplicate of this bug. ***
> Can we remove the quirk that allows paragraphs to contain tables from > standards mode? Done, see bug 91927. If it's "Save As" in Composer this bug is about then it's worksforme.
This should be cosed: wontfix in quirks mode, Worksforme in strict mode (see bug 91927).
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050919 Firefox/1.4 Yep, it works correctly in standards mode. Wontfix sounds reasonable for quirks mode.
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: