Closed Bug 292839 Opened 19 years ago Closed 19 years ago

textarea innerHTML doesn't handle entity references well

Categories

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

x86
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: stryker330, Unassigned)

References

Details

(Keywords: testcase)

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050502 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050502 Firefox/1.0+

Suppose a text node with value containing non-text PCDATA (e.g. 'some<br
/>markup') is appended to a textarea element.  Then, the text node's contents
are added unescaped/unencoded/unserialized (whatever it's called - the process
of converting '<' to '&lt;', etc.).

Also, the textarea element displays these contents "correctly" unescaped.  This
is probably the fallback behavior for invalid textarea contents.

Possible culprits:
- the act of appending the text node to the textarea
- textarea.innerHTML is incorrect (this seems unlikely)

Reproducible: Always

Steps to Reproduce:
1) var textnode = document.createTextNode('some<br />markup');
2) textarea.appendChild(textnode);
3) output textarea.innerHTML
Actual Results:  
some<br />markup

Expected Results:  
some&lt;br /&gt;markup
Attached file test case
Keywords: testcase
The DOM looks correct. Note that the creating/appending a textnode should not
unescape any HTML entities. createTextNode is not an html parser. there's also
no invalid contents involved. (compare the content model created by
data:text/html,<textarea>&lt;br/&gt;</textarea> )

Sounds to me like innerHTML is broken.
OS: Windows XP → All
The real problem is in the innerHTML getter and setter for <textarea>... they
try to do the right thing without fully reimplementing the whack parsing that
happens for textareas, but there are corner cases like this it ends up getting
wrong.

I'm pretty sure we have a bug on this already.
Summary: textarea will appendChild text node unescaped/unencoded/unserialized → textarea innerHTML doesn't handle entity references well
Whiteboard: DUPEME
Dupe of bug 215228?

> The DOM looks correct. Note that the creating/appending a textnode should not
> unescape any HTML entities. createTextNode is not an html parser. there's also
> no invalid contents involved. (compare the content model created by
> data:text/html,<textarea>&lt;br/&gt;</textarea> )
> 
> Sounds to me like innerHTML is broken.

Out of curiosity, when exactly are HTML entities supposed to be escaped?

document.createTextNode or node.appendChild or innerHTML(In reply to comment #2)
> Out of curiosity, when exactly are HTML entities supposed to be escaped?

In general, whenever the data will be parsed by an HTML parser.
Depends on: 293162
I think this got fixed when the fix for bug 152329 was checked in.
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Depends on: 152329
Resolution: --- → FIXED
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
Whiteboard: DUPEME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: