-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathurl-token-serialization.html
More file actions
70 lines (62 loc) · 2.38 KB
/
url-token-serialization.html
File metadata and controls
70 lines (62 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Variables: url() token serialization in custom properties</title>
<link rel="help" href="https://drafts.csswg.org/css-variables-2/#serializing-custom-props">
<link rel="help" href="https://drafts.csswg.org/css-syntax-3/#serialization">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="target"></div>
<script>
// "Specified values of custom properties must be serialized exactly as
// specified by the author. Simplifications that might occur in other
// properties, such as dropping comments, normalizing whitespace,
// reserializing numeric tokens from their value, etc., must not occur."
//
// The url() token value should not have its contents escaped using CSS
// identifier serialization rules. Characters like "." and "/" are valid
// in url() tokens and must not be backslash-escaped.
function test_url_roundtrip(input, description) {
test(function() {
var target = document.getElementById('target');
target.style.setProperty('--test', input);
var result = target.style.getPropertyValue('--test');
target.style.removeProperty('--test');
assert_equals(result, input);
}, description);
}
function test_url_serialization(input, expected, description) {
test(function() {
var target = document.getElementById('target');
target.style.setProperty('--test', input);
var result = target.style.getPropertyValue('--test');
target.style.removeProperty('--test');
assert_equals(result, expected);
}, description);
}
test_url_roundtrip(
'url(image.png)',
'Period in url() token must not be escaped'
);
test_url_roundtrip(
'url(path/to/image.png)',
'Slashes and periods in url() token must not be escaped'
);
test_url_roundtrip(
'url(https://example.com/image.png?q=1&v=2#frag)',
'Colons, slashes, periods, question marks, equals, ampersands, and hash in url() token must not be escaped'
);
test_url_roundtrip(
'url(~icons+set!v2)',
'Tilde, plus, and exclamation mark in url() token must not be escaped'
);
test_url_serialization(
'url(foo\\ bar)',
'url(foo\\ bar)',
'Escaped space in url() token must be serialized as an escape'
);
test_url_serialization(
'url(foo\\\tbar)',
'url(foo\\\tbar)',
'Escaped tab in url() token must be serialized as an escape'
);
</script>