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

Trusted types attributes #1268

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
67c0b7c
Draft integration with Trusted Types, take 2.
koto Jan 23, 2024
8b8555f
Added integration in 'set an attribute value'.
koto Jan 24, 2024
952f576
Removed stringification.
koto Jan 24, 2024
588bd9f
Fixed formatting.
koto Jan 25, 2024
72cf8f9
Fixed copy-paste error in setAttribute() and indentation.
koto Jan 25, 2024
cb2fdbb
Fix build
lukewarlow Mar 28, 2024
2a00536
Change code to pass sink values through to TT code.
lukewarlow Mar 28, 2024
316965c
Move validate and set attribute into append an attribute
lukewarlow Apr 10, 2024
8569042
Remove sink values from spec
lukewarlow Apr 11, 2024
7027be5
Revert changes to setAttributeNode and setAttributeNodeNS method steps
lukewarlow Apr 22, 2024
ac21ffe
Remove throw from set an attribute and move TT check down to replace …
lukewarlow Apr 22, 2024
03dc3fe
Revert unneeded changes
lukewarlow Apr 22, 2024
ae5ba7a
Address comment
lukewarlow Apr 22, 2024
3b607af
Add missing and
lukewarlow Apr 22, 2024
6726a50
Address some comments
lukewarlow May 7, 2024
93251d0
Re-add early return
lukewarlow May 7, 2024
0fbb13c
Change dfn to use given rather than with
lukewarlow May 7, 2024
e9280a4
Update how the enforcement is done
lukewarlow May 16, 2024
daa8d86
Add tentative enforcement for toggleAttribute
lukewarlow May 16, 2024
f8e9015
Update enforcement for toggleAttribute to match behaviour observed in…
lukewarlow May 16, 2024
7b4a995
Revert "Update enforcement for toggleAttribute to match behaviour obs…
lukewarlow Jun 11, 2024
0b3bc48
Revert "Add tentative enforcement for toggleAttribute"
lukewarlow Jun 11, 2024
d96fb19
Reintroduce infrastructure changes
lukewarlow Jun 13, 2024
73fa482
Add step to verify that the attr hasn't been assigned to another elem…
lukewarlow Feb 6, 2025
fdb686b
Run specfmt
lukewarlow Feb 6, 2025
b047352
Update set an attribute to verify attribute value as first step
lukewarlow Feb 20, 2025
5f234a4
Update set an existing attribute value
lukewarlow Feb 20, 2025
6b2fff6
Address editorial feedback
lukewarlow Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 95 additions & 21 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ spec:html; type:element
<p>This specification depends on the Infra Standard. [[!INFRA]]

<p>Some of the terms used in this specification are defined in <cite>Encoding</cite>,
<cite>Selectors</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and <cite>Namespaces in XML</cite>.
<cite>Selectors</cite>, <cite>Trusted Types</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
<cite>Namespaces in XML</cite>.
[[!ENCODING]]
[[!SELECTORS4]]
[[!TRUSTED-TYPES]]
[[!WEBIDL]]
[[!XML]]
[[!XML-NAMES]]
Expand Down Expand Up @@ -6213,8 +6215,8 @@ interface Element : Node {
sequence&lt;DOMString> getAttributeNames();
DOMString? getAttribute(DOMString qualifiedName);
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
[CEReactions] undefined setAttribute(DOMString qualifiedName, (TrustedType or DOMString) value);
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, (TrustedType or DOMString) value);
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
Expand Down Expand Up @@ -6589,6 +6591,14 @@ steps:
<a for=Attr>value</a>.
</ol>

<p>To <dfn>verify attribute value</dfn> given a {{TrustedType}} or string <var>value</var>, an
<a>attribute</a> <var>attribute</var>, and an <a for=/>Element</a> <var>element</var>:

<ol>
<li><p>Return the result of calling <a abstract-op>get Trusted Types-compliant attribute value</a>
given <var>attribute</var>, with <var>element</var>, and <var>value</var>. [[!TRUSTED-TYPES]]
</ol>

<hr>

<div algorithm>
Expand Down Expand Up @@ -6641,6 +6651,9 @@ string <var>namespace</var> (default null):</p>
<a for=/>attribute</a> <var>attr</var> and an <a for=/>element</a> <var>element</var>:

<ol>
<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
Copy link
Member

Choose a reason for hiding this comment

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

"result of verifying an attribute value"

given <var>attr</var>'s <a for=Attr>value</a>, <var>attr</var>, and <var>element</var>.

<li><p>If <var>attr</var>'s <a for=Attr>element</a> is neither null nor <var>element</var>,
<a>throw</a> an "{{InUseAttributeError!!exception}}" {{DOMException}}.

Expand All @@ -6656,29 +6669,57 @@ string <var>namespace</var> (default null):</p>

<li><p>Otherwise, <a lt="append an attribute">append</a> <var>attr</var> to <var>element</var>.

<li><p>Set <var>attr</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p>Return <var>oldAttr</var>.
</ol>
</div>

<div algorithm>
<p>To <dfn export id=concept-element-attributes-set-value>set an attribute value</dfn> given an
<a for=/>element</a> <var>element</var>, a string <var>localName</var>, a string <var>value</var>,
an optional null or string <var>prefix</var> (default null), and an optional null or string
<var>namespace</var> (default null):
<p>To <dfn export id=concept-element-attributes-set-value>set an attribute value</dfn> given an <a
Copy link
Member

Choose a reason for hiding this comment

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

No wrapping in phrasing-level elements.

for=/>element</a> <var>element</var>, a string <var>localName</var>, a string or {{TrustedType}}
<var>value</var>, an optional null or string <var>prefix</var> (default null), an optional null or
string <var>namespace</var> (default null), and an optional boolean <var>verify</var> (default
false):

<ol>
<li>Let <var>attribute</var> be the result of
<a lt="get an attribute by namespace and local name">getting an attribute</a> given
<var>namespace</var>, <var>localName</var>, and <var>element</var>.

<li>If <var>attribute</var> is null, create an <a>attribute</a> whose <a for=Attr>namespace</a> is
<var>namespace</var>, <a for=Attr>namespace prefix</a> is <var>prefix</var>,
<a for=Attr>local name</a> is <var>localName</var>, <a for=Attr>value</a> is <var>value</var>, and
<a for=Node>node document</a> is <var>element</var>'s <a for=Node>node document</a>, then
<a lt="append an attribute">append</a> this <a>attribute</a> to <var>element</var>, and then
return.
<li><p>Let <var>attributeExists</var> be false if <var>attribute</var> is null; otherwise true.

<li><p>If <var>attributeExists</var> is false, set <var>attribute</var> to an <a>attribute</a>
Copy link
Member

Choose a reason for hiding this comment

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

then set

whose <a for=Attr>namespace</a> is <var>namespace</var>, <a for=Attr>namespace prefix</a> is
<var>prefix</var>, <a for=Attr>local name</a> is <var>localName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <var>element</var>'s <a for=Node>node
Copy link
Member

Choose a reason for hiding this comment

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

No wrapping in phrasing

document</a>.

<li><p>Let <var>verifiedValue</var> be <var>value</var>.

<li>
<p>If <var>verify</var> is true:

<ol>
<li><p>Set <var>verifiedValue</var> to the result of calling <a>verify attribute value</a>
Copy link
Member

Choose a reason for hiding this comment

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

"result of verifying an attribute" is nicer. And it should work with Bikeshed.

given <var>value</var>, <var>attribute</var>, and <var>element</var>.

<li><p>Set <var>attributeExists</var> to true if <var>element</var>
<a lt="has an attribute">has an attribute</a> <var>attribute</var>; otherwise false.
</ol>
</li>

<li><p>If <var>attributeExists</var> is true, <a lt="change an attribute">change</a>
<var>attribute</var> to <var>verifiedValue</var>.

<li>
<p>Otherwise:

<ol>
<li><p>Set <var>attribute</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>value</var>.
<li><p><a lt="append an attribute">Append</a> this <a>attribute</a> to <var>element</var>.
</ol>
</ol>
</div>

Expand Down Expand Up @@ -6939,12 +6980,29 @@ method steps are:
and null otherwise.
<!-- This is step 2 of "get an attribute by name", modified as appropriate -->

<li><p>If <var>attribute</var> is null, create an <a>attribute</a> whose
<a for=Attr>local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <a>this</a>'s <a for=Node>node document</a>,
then <a lt="append an attribute">append</a> this <a>attribute</a> to <a>this</a>, and then return.
<li><p>Let <var>attributeExists</var> be false if <var>attribute</var> is null; otherwise true.

<li><p>If <var>attributeExists</var> is false, set <var>attribute</var> to an <a>attribute</a>
whose <a for=Attr>local name</a> is <var>qualifiedName</var>, <a for=Attr>value</a> is
<var>value</var>, and <a for=Node>node document</a> is <a>this</a>'s <a for=Node>node document</a>.

<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
Copy link
Member

Choose a reason for hiding this comment

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

"result of verifying"

given <var>value</var>, <var>attribute</var>, and <a>this</a>.

<li><p>Set <var>attributeExists</var> to true if <a>this</a>
<a lt="has an attribute">has an attribute</a> <var>attribute</var>; otherwise false.

<li><p>If <var>attributeExists</var> is true, <a lt="change an attribute">change</a>
<var>attribute</var> to <var>verifiedValue</var>.

<li>
<p>Otherwise:

<ol>
<li><p>Set <var>attribute</var>'s <a for=Attr>value</a> to <var>verifiedValue</var>.

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>value</var>.
<li><p><a lt="append an attribute">Append</a> this <a>attribute</a> to <var>element</var>.
</ol>
</ol>

<p>The
Expand All @@ -6956,7 +7014,7 @@ method steps are:
passing <var>namespace</var> and <var>qualifiedName</var> to <a>validate and extract</a>.

<li><p><a>Set an attribute value</a> for <a>this</a> using <var>localName</var>, <var>value</var>,
and also <var>prefix</var> and <var>namespace</var>.
<var>prefix</var>, <var>namespace</var> and true.
</ol>

<p>The
Expand Down Expand Up @@ -7514,7 +7572,23 @@ string <var>value</var>, run these steps:
<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is null, then set <var>attribute</var>'s
<a for=Attr>value</a> to <var>value</var>.

<li><p>Otherwise, <a lt="change an attribute">change</a> <var>attribute</var> to <var>value</var>.
<li>
<p>Otherwise:

<ol>
<li><p>Let <var>originalElement</var> be <var>attribute</var>'s <a for=Attr>element</a>.

<li><p>Let <var>verifiedValue</var> be the result of calling <a>verify attribute value</a>
given <var>value</var>, <var>attribute</var>, and <a>this</a>.

<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is null, then set <var>attribute</var>'s
<a for=Attr>value</a> to <var>value</var>, and return.

<li><p>If <var>attribute</var>'s <a for=Attr>element</a> is not <var>originalElement</var>, then
return.

<li><p><a lt="change an attribute">Change</a> <var>attribute</var> to <var>verifiedValue</var>.
</ol>
</ol>

<p>The {{Attr/value}} setter steps are to <a>set an existing attribute value</a> with <a>this</a>
Expand Down