-
Notifications
You must be signed in to change notification settings - Fork 22.7k
FF140 escaping <
and >
to <
and >
in attributes when serializing HTML
#39639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
141fed8
9feafb7
9756ee3
aef4e20
faec0ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,32 +9,27 @@ browser-compat: api.Element.outerHTML | |
{{APIRef("DOM")}} | ||
|
||
The **`outerHTML`** attribute of the {{ domxref("Element") }} | ||
DOM interface gets the serialized HTML fragment describing the element including its | ||
descendants. It can also be set to replace the element with nodes parsed from the given | ||
string. | ||
DOM interface gets the serialized HTML fragment describing the element including its descendants. | ||
It can also be set to replace the element with nodes parsed from the given string. | ||
|
||
To only obtain the HTML representation of the contents of an element, or to replace the | ||
contents of an element, use the {{domxref("Element.innerHTML", "innerHTML")}} property | ||
instead. | ||
To only obtain the HTML representation of the contents of an element, or to replace the contents of an element, use the {{domxref("Element.innerHTML", "innerHTML")}} property instead. | ||
|
||
Note that some browsers serialize `<` and `>` in attributes as `<` and `>` when reading the HTML (see [Browser compatibility](#browser_compatibility)). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only actual change in this page. |
||
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML. | ||
|
||
## Value | ||
|
||
Reading the value of `outerHTML` returns a string | ||
containing an HTML serialization of the `element` and its descendants. | ||
Setting the value of `outerHTML` replaces the element and all of its | ||
descendants with a new DOM tree constructed by parsing the specified | ||
`htmlString`. | ||
Reading the value of `outerHTML` returns a string containing an HTML serialization of the `element` and its descendants. | ||
Setting the value of `outerHTML` replaces the element and all of its descendants with a new DOM tree constructed by parsing the specified `htmlString`. | ||
|
||
When set to the `null` value, that `null` value is converted to the empty string (`""`), so `elt.outerHTML = null` is equivalent to `elt.outerHTML = ""`. | ||
|
||
### Exceptions | ||
|
||
- `SyntaxError` {{domxref("DOMException")}} | ||
- : Thrown if an attempt was made to set `outerHTML` using an HTML string which is not | ||
valid. | ||
- : Thrown if an attempt was made to set `outerHTML` using an HTML string which is not valid. | ||
- `NoModificationAllowedError` {{domxref("DOMException")}} | ||
- : Thrown if an attempt was made to set `outerHTML` on an element which is a direct | ||
child of a {{domxref("Document")}}, such as {{domxref("Document.documentElement")}}. | ||
- : Thrown if an attempt was made to set `outerHTML` on an element which is a direct child of a {{domxref("Document")}}, such as {{domxref("Document.documentElement")}}. | ||
|
||
## Examples | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ browser-compat: api.ShadowRoot.innerHTML | |
|
||
{{APIRef("Shadow DOM")}} | ||
|
||
The **`innerHTML`** property of the {{domxref("ShadowRoot")}} | ||
interface sets or returns a reference to the DOM tree inside the | ||
`ShadowRoot`. | ||
The **`innerHTML`** property of the {{domxref("ShadowRoot")}} interface sets gets or sets the HTML markup to the DOM tree inside the `ShadowRoot`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text here seemed completely wrong - it isn't a reference. There is a lot more that can be said. I don't want to say it in this PR because that would be out of scope for this task. I do expect to be back here though, as I am currently doing work on the HTLM sanitization API which tanjentially affects this. I will also be looking at it as I add docs on the injection sinks for TrustedTypes. |
||
|
||
Note that some browsers serialize `<` and `>` in attributes as `<` and `>` when reading the HTML (see [Browser compatibility](#browser_compatibility)). | ||
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML. | ||
|
||
## Value | ||
|
||
|
@@ -20,6 +21,8 @@ When set to the `null` value, that `null` value is converted to the empty string | |
|
||
## Examples | ||
|
||
### Setting the innerHTML of a Shadow root | ||
|
||
```js | ||
let customElem = document.querySelector("my-shadow-dom-element"); | ||
let shadow = customElem.shadowRoot; | ||
|
Uh oh!
There was an error while loading. Please reload this page.