Skip to content

Commit 5b28aaa

Browse files
committed
[css-values-4] Add fetch() as a variant of url() that doesn't accept unquoted values. #541
1 parent ca00007 commit 5b28aaa

File tree

1 file changed

+64
-29
lines changed

1 file changed

+64
-29
lines changed

css-values-4/Overview.bs

+64-29
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ At Risk: ''toggle()'', ''attr()''
1515
Ignored Terms: <spacing-limit>, containing block
1616
Ignored Vars: Cn+1, n
1717
Inline Github Issues: yes
18+
Default Highlight: css
1819
</pre>
1920
<pre class='link-defaults'>
2021
spec: css-backgrounds-3; type: type; text: <position>
@@ -459,11 +460,11 @@ Textual Data Types</h2>
459460
the <a lt="specified value">specified</a> and <a>computed value</a> of a property
460461
are exactly the provided Unicode values after parsing
461462
(which includes character set conversion and [[css-syntax-3#escaping|escaping]]).
462-
[[!UNICODE]] [[!CSS3SYN]]
463+
[[!UNICODE]] [[!CSS-SYNTAX-3]]
463464

464465
<dfn export lt="CSS identifier | CSS ident | identifier | ident">CSS identifiers</dfn>,
465466
generically denoted by <dfn>&lt;ident></dfn>,
466-
consist of a sequence of characters conforming to the <<ident-token>> grammar. [[!CSS3SYN]]
467+
consist of a sequence of characters conforming to the <<ident-token>> grammar. [[!CSS-SYNTAX-3]]
467468
Identifiers cannot be quoted;
468469
otherwise they would be interpreted as strings.
469470
CSS properties accept two classes of <a>identifiers</a>:
@@ -657,7 +658,7 @@ Quoted Strings: the <<string>> type</h3>
657658
[=Strings=] are denoted by <dfn id="string-value">&lt;string></dfn>
658659
and consist of a sequence of characters delimited by double quotes or
659660
single quotes. They correspond to the <<string-token>> production
660-
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
661+
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
661662

662663
<div class=example>
663664
Double quotes cannot occur inside double quotes, unless
@@ -706,51 +707,85 @@ Quoted Strings: the <<string>> type</h3>
706707
<h3 id="urls">
707708
Resource Locators: the <<url>> type</h3>
708709

709-
The <dfn>url()</dfn> <a>functional notation</a>,
710-
denoted by <<url>>,
710+
The <<url>> type
711711
represents a <l spec=url>[=/URL=]</l>,
712712
which is a pointer to a resource.
713-
The typical syntax of a <<url>> is:
714713

715-
<pre class="prod"><dfn id="url-value">&lt;url></dfn> = url( <<string>> <<url-modifier>>* )</pre>
714+
Typically, a <<url>> is written with the <dfn>url()</dfn>
715+
or <dfn>fetch()</dfn> <a>functional notations</a>:
716+
717+
<pre class="prod">
718+
<dfn id="url-value">&lt;url></dfn> = url( <<string>> <<url-modifier>>* ) |
719+
fetch( <<string>> <<url-modifier>>* )
720+
</pre>
716721

717722
<div class="example">
718-
Below is an example of a URL being used as a background image:
723+
This example shows a URL being used as a background image:
719724

720-
<pre>body { background: url("http://www.example.com/pinkish.gif") }</pre>
725+
<pre highlight=css>
726+
body { background: url("http://www.example.com/pinkish.gif") }
727+
</pre>
721728
</div>
722729

723-
A <<url>> may alternately be written without quotation marks around the URL itself,
730+
For legacy reasons, a ''url()'' can be written without quotation marks around the URL itself,
724731
in which case it is <a lt="consume a url token" spec=css-syntax-3>specially-parsed</a>
725-
as a <<url-token>> [[!CSS3SYN]].
732+
as a <<url-token>> [[!CSS-SYNTAX-3]].
733+
Because of this special parsing, ''url()'' is only able to specify its URL literally;
734+
''fetch()'' lacks this special parsing rule,
735+
and so its URL can be provided by functions,
736+
such as ''var()''.
726737

727738
<div class="example">
728739
For example, the following declarations are identical:
740+
729741
<pre>
730742
background: url("http://www.example.com/pinkish.gif");
731743
background: url(http://www.example.com/pinkish.gif);
732744
</pre>
745+
746+
And these have the same meaning as well:
747+
748+
<pre>
749+
background: fetch("http://www.example.com/pinkish.gif");
750+
--foo: "http://www.example.com/pinkish.gif";
751+
background: fetch(var(--foo));
752+
</pre>
753+
754+
But this does <em>not</em> work:
755+
756+
<pre>
757+
--foo: "http://www.example.com/pinkish.gif";
758+
background: url(var(--foo));
759+
</pre>
760+
761+
...because the unescaped "(" in the value causes a parse error,
762+
so the entire declaration is thrown out as invalid.
733763
</div>
734764

735-
Note: This unquoted syntax cannot accept a <<url-modifier>> argument
736-
and has extra escaping requirements:
737-
parentheses, <a href="https://www.w3.org/TR/css-syntax/#whitespace">whitespace</a> characters,
738-
single quotes (&#39;) and double quotes (") appearing in a URL
739-
must be escaped with a backslash,
740-
e.g. ''url(open\(parens)'', ''url(close\)parens)''.
741-
(In quoted <<string>> ''url()''s,
742-
only newlines and the character used to quote the string need to be escaped.)
743-
Depending on the type of URL,
744-
it might also be possible to write these characters as URL-escapes
745-
(e.g. ''url(open%28parens)'' or ''url(close%29parens)'')
746-
as described in [[URL]].
765+
<div class=note>
766+
The unquoted ''url()'' syntax cannot accept a <<url-modifier>> argument
767+
and has extra escaping requirements:
768+
parentheses, <a href="https://www.w3.org/TR/css-syntax/#whitespace">whitespace</a> characters,
769+
single quotes (&#39;) and double quotes (") appearing in a URL
770+
must be escaped with a backslash,
771+
e.g. ''url(open\(parens)'', ''url(close\)parens)''.
772+
(In quoted <<string>> ''url()''s,
773+
only newlines and the character used to quote the string need to be escaped.)
774+
Depending on the type of URL,
775+
it might also be possible to write these characters as URL-escapes
776+
(e.g. ''url(open%28parens)'' or ''url(close%29parens)'')
777+
as described in [[URL]].
778+
779+
The precise requirements for parsing the unquoted ''url()'' syntax
780+
are normatively defined in [[!CSS-SYNTAX-3]].
781+
</div>
747782

748783
Some CSS contexts (such as ''@import'') also allow a <<url>>
749-
to be represented by a bare <<string>>, without the ''url()'' wrapper.
784+
to be represented by a bare <<string>>, without the function wrapper.
750785
In such cases the string behaves identically to a ''url()'' function containing that string.
751786

752787
<div class="example">
753-
For example, the following statements are identical:
788+
For example, the following statements act identically:
754789
<pre>
755790
@import url("base-theme.css");
756791
@import "base-theme.css";
@@ -950,7 +985,7 @@ Integers: the <<integer>> type</h3>
950985
When written literally,
951986
an <dfn export>integer</dfn> is one or more decimal digits ''0'' through ''9''
952987
and corresponds to a subset of the <<number-token>> production
953-
in the CSS Syntax Module [[!CSS3SYN]].
988+
in the CSS Syntax Module [[!CSS-SYNTAX-3]].
954989
The first digit of an integer may be immediately preceded by <css>-</css> or <css>+</css>
955990
to indicate the integer's sign.
956991

@@ -996,7 +1031,7 @@ Real Numbers: the <<number>> type</h3>
9961031
or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits
9971032
and optionally an exponent composed of "e" or "E" and an integer.
9981033
It corresponds to the <<number-token>> production
999-
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
1034+
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
10001035
As with integers, the first character of a number may be immediately preceded by <css>-</css> or <css>+</css>
10011036
to indicate the number's sign.
10021037

@@ -1031,7 +1066,7 @@ Numbers with Units: <a>dimension</a> values</h3>
10311066
immediately followed by a unit identifier,
10321067
which is an <a>identifier</a>.
10331068
It corresponds to the <<dimension-token>> production
1034-
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
1069+
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
10351070
Like keywords, unit identifiers are <a>ASCII case-insensitive</a>.
10361071

10371072
<wpt>
@@ -1104,7 +1139,7 @@ Percentages: the <<percentage>> type</h3>
11041139
a <dfn export>percentage</dfn> consists of a <a>number</a>
11051140
immediately followed by a percent sign <css>%</css>.
11061141
It corresponds to the <<percentage-token>> production
1107-
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS3SYN]].
1142+
in the <a href="https://www.w3.org/TR/css-syntax/">CSS Syntax Module</a> [[!CSS-SYNTAX-3]].
11081143

11091144
Percentage values are always relative to another quantity,
11101145
for example a length.

0 commit comments

Comments
 (0)