Skip to content

Commit 14ae4f6

Browse files
andruudAnders Hartvoll Ruud
andauthored
[css-values-5] Handle attr() cycles (#11459)
Co-authored-by: Anders Hartvoll Ruud <andruud@google.com>
1 parent 1491632 commit 14ae4f6

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

css-values-5/Overview.bs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,69 @@ Security</h4>
17911791
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
17921792
needs to be invalid as well.
17931793

1794+
<h4 id=attr-cycles>
1795+
Cycles</h4>
1796+
1797+
An attribute value may contain ''attr()'' functions,
1798+
or other [=arbitrary substitution functions=],
1799+
that are substituted during [=parse with a &lt;syntax>=].
1800+
This can cause cyclic dependecies,
1801+
either by an attribute referring to itself,
1802+
through multiple attributes referring to each other,
1803+
or through a combination of other [=arbitrary substitution functions=]
1804+
(e.g. ''var()'').
1805+
1806+
For each element, add a node for every attribute on that element
1807+
to the graph described in [[css-variables-1#cycles]].
1808+
Then, for each attribute <var>attrib</var>,
1809+
add edges as follows:
1810+
1811+
* From <var>attrib</var> to any attributes referenced by ''attr()''
1812+
within <var>attrib</var>'s value.
1813+
* From <var>attrib</var> to any [=custom properties=] referenced by ''var()''
1814+
within <var>attrib</var>'s value.
1815+
* From any [=custom property=] that references <var>attrib</var> using ''attr()''
1816+
to <var>attrib</var>.
1817+
1818+
An ''attr()'' referencing an attribute
1819+
which is part of a cycle
1820+
makes the containing [=declaration=] [=invalid at computed-value time=].
1821+
1822+
<div class='example'>
1823+
In the following,
1824+
<code>width</code> is [=invalid at computed-value time=],
1825+
because ''attr()'' tries to substitute a value which refers to itself:
1826+
1827+
<pre class='lang-css'>
1828+
div {
1829+
width: attr(data-foo type(*));
1830+
}
1831+
</pre>
1832+
<pre class='lang-html'>
1833+
&lt;div data-foo="attr(data-foo type(*))">&lt;/div>
1834+
</pre>
1835+
1836+
Note: Even if one (or both) of the ''attr()'' functions had a fallback,
1837+
the result would be the same.
1838+
</div>
1839+
1840+
<div class='example'>
1841+
Cycles can occur through [=custom properties=];
1842+
in the following,
1843+
<code>--x</code> and <code>--y</code> are both [=invalid at computed-value time=]:
1844+
1845+
<pre class='lang-css'>
1846+
div {
1847+
--x: var(--y);
1848+
--y: attr(data-foo type(*));
1849+
}
1850+
</pre>
1851+
<pre class='lang-html'>
1852+
&lt;div data-foo="var(--x)">&lt;/div>
1853+
</pre>
1854+
</div>
1855+
1856+
17941857
<!-- Big Text: random
17951858

17961859
████▌ ███▌ █ █▌ ████▌ ███▌ █ █

0 commit comments

Comments
 (0)