Skip to content
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

Add setHTMLUnsafe and parseHTMLUnsafe methods #9538

Merged
merged 27 commits into from Oct 11, 2023
Merged

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Jul 20, 2023

@josepharhar josepharhar marked this pull request as ready for review August 8, 2023 21:30
@josepharhar
Copy link
Contributor Author

@otherdaniel @mikewest

Copy link
Member

@mikewest mikewest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. A few comments inline, though I'd suggest it would be useful to get an HTML editor's opinion about the right way to do this integration. @domenic might have time?

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@domenic domenic added addition/proposal New features or enhancements topic: parser labels Aug 14, 2023
Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so the main remaining issue to be discussed do we want the template retargeting behavior, where templateEl.setHTMLUnsafe(string) modifies templateEl.contents instead of templateEl directly?

I tend to say yes. Although it's a bit magical:

  • There's really never a situation where you want to actually modify children of the template element itself.
  • If we were different from innerHTML, that would probably be surprising.
  • If we don't add this, it's pretty difficult to update the template element's contents from a string.

The last one could be fixed, by adding setHTMLUnsafe() to DocumentFragment. (Then, templateEl.contents.setHTMLUnsafe() would work.) That might be a good idea anyway; I feel like I've seen lots of threads asking for it? Edit: I found the thread I was thinking of and I remember why this is hard. You lose the potential context. Which was a big debate in the sanitizer API circles already. So, let's not couple that to this :).

To expand on "it's a bit magical", the downside is basically that templateEl.replaceChildren(foo) or templateEl.appendChild(foo) will change the template element's contents directly, so maybe templateEl.setHTMLUnsafe(foo) should follow that pattern instead of following templateEl.innerHTML = foo.

Hmm, related question: should this method also exist on ShadowRoot, like innerHTML does?

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@mfreed7
Copy link
Collaborator

mfreed7 commented Aug 21, 2023

OK, so the main remaining issue to be discussed do we want the template retargeting behavior, where templateEl.setHTMLUnsafe(string) modifies templateEl.contents instead of templateEl directly?

I tend to say yes. Although it's a bit magical:

  • There's really never a situation where you want to actually modify children of the template element itself.
  • If we were different from innerHTML, that would probably be surprising.
  • If we don't add this, it's pretty difficult to update the template element's contents from a string.

The last one could be fixed, by adding setHTMLUnsafe() to DocumentFragment. (Then, templateEl.contents.setHTMLUnsafe() would work.) That might be a good idea anyway; I feel like I've seen lots of threads asking for it? Edit: I found the thread I was thinking of and I remember why this is hard. You lose the potential context. Which was a big debate in the sanitizer API circles already. So, let's not couple that to this :).

To expand on "it's a bit magical", the downside is basically that templateEl.replaceChildren(foo) or templateEl.appendChild(foo) will change the template element's contents directly, so maybe templateEl.setHTMLUnsafe(foo) should follow that pattern instead of following templateEl.innerHTML = foo.

I tend to agree with you - I think element.setHTMLUnsafe(foo) should behave as closely as possible to element.innerHTML = foo, to avoid confusion. And as you point out, it's a convenience feature to avoid the footgun of setting <template>'s actual children. Setting template content has always been a bit magical, and I think this new method should follow that magic pattern.

Hmm, related question: should this method also exist on ShadowRoot, like innerHTML does?

Seems like it really should. @josepharhar seems like something to add?

@josepharhar
Copy link
Contributor Author

Hmm, related question: should this method also exist on ShadowRoot, like innerHTML does?

Seems like it really should. @josepharhar seems like something to add?

I'd need to figure out how to make the "context" element in this algorithm also be a shadowroot:
https://html.spec.whatwg.org/multipage/parsing.html#html-fragment-parsing-algorithm

There is at least one spot that seems nontrivial to modify:

Create a start tag token whose name is the local name of context and whose attributes are the attributes of context.

@domenic
Copy link
Member

domenic commented Aug 22, 2023

I think the best way to do that is:

  • Extract all of what is currently setHTMLUnsafe() into something like "unsafe set HTML steps" given contextNode, target, and string.
  • Change Element's setHTMLUnsafe() to call "unsafe set HTML steps" given this, this and string
  • Define ShadowRoot's setHTMLUnsafe() to call "unsafe set HTML steps" given this's shadow host, this, and string.

@josepharhar
Copy link
Contributor Author

given this's shadow host

Ok cool I wasn't sure if this was how it should work, thanks! I applied your suggestions

source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the declarative shadow tree PR be made ready for merge first? Currently this PR suggests some shared code paths that are meant to not be shared. I.e., DOMParser and parseUnsafeHTML will deal with declarative shadow trees differently.

source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@josepharhar josepharhar deleted the sethtml branch October 11, 2023 23:22
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2023
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2023
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
aarongable pushed a commit to chromium/chromium that referenced this pull request Oct 16, 2023
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2023
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Oct 16, 2023
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Oct 26, 2023
…afe, a=testonly

Automatic update from web-platform-tests
Implement parseHTMLUnsafe and setHTMLUnsafe

I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}

--

wpt-commits: 17743f761d9f8bd3954bc68c60b88d251f9a2239
wpt-pr: 41704
ErichDonGubler pushed a commit to ErichDonGubler/firefox that referenced this pull request Oct 27, 2023
…afe, a=testonly

Automatic update from web-platform-tests
Implement parseHTMLUnsafe and setHTMLUnsafe

I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}

--

wpt-commits: 17743f761d9f8bd3954bc68c60b88d251f9a2239
wpt-pr: 41704
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 30, 2023
…afe, a=testonly

Automatic update from web-platform-tests
Implement parseHTMLUnsafe and setHTMLUnsafe

I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Joey Arhar <jarharchromium.org>
Cr-Commit-Position: refs/heads/main{#1210412}

--

wpt-commits: 17743f761d9f8bd3954bc68c60b88d251f9a2239
wpt-pr: 41704

UltraBlame original commit: 27a50ba5472ea3cd6771918695f14558391747fd
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 30, 2023
…afe, a=testonly

Automatic update from web-platform-tests
Implement parseHTMLUnsafe and setHTMLUnsafe

I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Joey Arhar <jarharchromium.org>
Cr-Commit-Position: refs/heads/main{#1210412}

--

wpt-commits: 17743f761d9f8bd3954bc68c60b88d251f9a2239
wpt-pr: 41704

UltraBlame original commit: 27a50ba5472ea3cd6771918695f14558391747fd
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 30, 2023
…afe, a=testonly

Automatic update from web-platform-tests
Implement parseHTMLUnsafe and setHTMLUnsafe

I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Joey Arhar <jarharchromium.org>
Cr-Commit-Position: refs/heads/main{#1210412}

--

wpt-commits: 17743f761d9f8bd3954bc68c60b88d251f9a2239
wpt-pr: 41704

UltraBlame original commit: 27a50ba5472ea3cd6771918695f14558391747fd
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 27, 2023
Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
aarongable pushed a commit to chromium/chromium that referenced this pull request Nov 27, 2023
Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 27, 2023
Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Nov 27, 2023
Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Dec 2, 2023
…, a=testonly

Automatic update from web-platform-tests
Remove tentative from setHTMLUnsafe WPTs

Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}

--

wpt-commits: 8219cf1619ccb622f8ae0d9e61ed273f80991124
wpt-pr: 43343
vinnydiehl pushed a commit to vinnydiehl/mozilla-unified that referenced this pull request Dec 3, 2023
…, a=testonly

Automatic update from web-platform-tests
Remove tentative from setHTMLUnsafe WPTs

Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}

--

wpt-commits: 8219cf1619ccb622f8ae0d9e61ed273f80991124
wpt-pr: 43343
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Dec 7, 2023
…, a=testonly

Automatic update from web-platform-tests
Remove tentative from setHTMLUnsafe WPTs

Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarharchromium.org>
Reviewed-by: David Baron <dbaronchromium.org>
Cr-Commit-Position: refs/heads/main{#1229582}

--

wpt-commits: 8219cf1619ccb622f8ae0d9e61ed273f80991124
wpt-pr: 43343

UltraBlame original commit: 046a9d44fcc7527faaceee93ab34b1851c1a5e5a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Dec 7, 2023
…, a=testonly

Automatic update from web-platform-tests
Remove tentative from setHTMLUnsafe WPTs

Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarharchromium.org>
Reviewed-by: David Baron <dbaronchromium.org>
Cr-Commit-Position: refs/heads/main{#1229582}

--

wpt-commits: 8219cf1619ccb622f8ae0d9e61ed273f80991124
wpt-pr: 43343

UltraBlame original commit: 046a9d44fcc7527faaceee93ab34b1851c1a5e5a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Dec 7, 2023
…, a=testonly

Automatic update from web-platform-tests
Remove tentative from setHTMLUnsafe WPTs

Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarharchromium.org>
Reviewed-by: David Baron <dbaronchromium.org>
Cr-Commit-Position: refs/heads/main{#1229582}

--

wpt-commits: 8219cf1619ccb622f8ae0d9e61ed273f80991124
wpt-pr: 43343

UltraBlame original commit: 046a9d44fcc7527faaceee93ab34b1851c1a5e5a
ns-rsilva pushed a commit to ns-rsilva/chromium that referenced this pull request Apr 25, 2024
I am speccing this here: whatwg/html#9538

Bug: 1478969
Change-Id: Ie55827cebdf349aadae13fbf1086baf6177bbff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4824679
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210412}

Former-commit-id: 28866ee42d8313519a633dc76543ebb2418b2e7d
ns-rsilva pushed a commit to ns-rsilva/chromium that referenced this pull request Apr 25, 2024
Now that the HTML spec PR has been merged, we can remove the tentative
from the filename: whatwg/html#9538

Change-Id: I3f73a4c8040828b8cbf0939ba7f8fac9addc1803
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5059429
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229582}

Former-commit-id: 2b0f3ebf4d01b01e4ff5bdfbd1da484af109791c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation topic: parser
Development

Successfully merging this pull request may close these issues.

None yet

6 participants