Closed Bug 1579186 Opened 5 years ago Closed 4 years ago

element.innerText within an <foreignObject> is incorrect

Categories

(Core :: SVG, defect, P3)

69 Branch
defect

Tracking

()

RESOLVED FIXED
mozilla79
Webcompat Priority ?
Tracking Status
firefox79 --- fixed

People

(Reporter: itszn, Assigned: longsonr)

References

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36

Steps to reproduce:

Load an html file with the following content:

<html>
<body>
<svg><foreignObject><span id="x">hello</span></foreignObject></svg>
<script>
alert(x.innerText)
</script>
</body>
</html>

Actual results:

x.innerText returned an empty string

Expected results:

x.innerText should return "hello"

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → SVG
Product: Firefox → Core

I can reproduce this on Firefox 71 nightly today by https://jsfiddle.net/utrny7xj/. The definition of innerText says it should include its descendants. However, foreignObject is kind of a different XML namespace. I'm not sure if it is the expected result on Firefox. Chrome seems correct, anyway.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

I didn't look closely at if the standards say it should do this, but innerText within <foreignObject> works on Chrome, Edge, and Safari (I noticed this when an app wasn't working on firefox but worked everywhere else). Also innerHTML and textContent work as expected with <foreignObject> in Firefox.

Attached file reporters testcase
Assignee: nobody → longsonr
Status: NEW → ASSIGNED
Attached file 54188.html

We've got a report that seems to be related to this issue, except the child element is a contenteditable div. I've attached a reduced test case.

The site is using the following code:

{
                key: "onInput",
                value: function() {
                    var e = this.foreignObject.firstElementChild;
                    this.text = e.innerText,
                    this.setSize(u.svgTextSize(this.text, this.props)),
                    this.textNode.innerHTML = u.svgText(this.text, this.props).innerHTML,
                    this.changed(l.TEXT_LAYER_INPUT_CHANGE, {
                        id: this.contentId,
                        text: this.text
                    })
                }
            } 

e.innerText is an empty string in this case, similarly to the initial testcase, which causes an issue with calculations later on in this.setSize.

Webcompat Priority: --- → ?
Pushed by longsonr@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/f97fcfd4a045
element.innerText should work with SVG text and foreignObject text r=dholbert
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/24300 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla79
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: