Skip to content

Commit 8765511

Browse files
committed
fixup! Fix #11, #12: quote attributes that need escaping in legacy browsers
1 parent 15ff801 commit 8765511

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

CHANGES.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ Released on XXX
3333
* **Use scripting disabled by default (as we don't implement
3434
scripting).**
3535

36-
* Fix #11, avoiding the XSS bug potentially caused by serializer allowing
37-
attribute values to be escaped out of in old browser versions, changing
38-
the quote_attr_values option on serializer to take one of three values,
39-
"always" (the old True value), "legacy" (the new option, and the new
40-
default), and "spec" (the old False value, and the old default).
36+
* **Fix #11, avoiding the XSS bug potentially caused by serializer
37+
allowing attribute values to be escaped out of in old browser versions,
38+
changing the quote_attr_values option on serializer to take one of
39+
three values, "always" (the old True value), "legacy" (the new option,
40+
and the new default), and "spec" (the old False value, and the old
41+
default).**
4142

4243

4344
0.9999999/1.0b8

html5lib/serializer/htmlserializer.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,11 @@ def serialize(self, treewalker, encoding=None):
248248
(k not in booleanAttributes.get(name, tuple()) and
249249
k not in booleanAttributes.get("", tuple())):
250250
yield self.encodeStrict("=")
251-
if (self.quote_attr_values == "always" or
252-
self.quote_attr_values is True or
253-
len(v) == 0):
251+
if self.quote_attr_values == "always" or len(v) == 0:
254252
quote_attr = True
255253
elif self.quote_attr_values == "spec":
256254
quote_attr = quoteAttributeSpec.search(v) is not None
257-
elif (self.quote_attr_values == "legacy" or
258-
self.quote_attr_values is False):
255+
elif self.quote_attr_values == "legacy":
259256
quote_attr = quoteAttributeLegacy.search(v) is not None
260257
else:
261258
raise ValueError("quote_attr_values must be one of: "

html5lib/tests/serializer-testdata/options.test

+4-27
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
]
4242
]
4343
],
44-
"description": "quote_attr_values=true",
44+
"description": "quote_attr_values='always'",
4545
"options": {
46-
"quote_attr_values": true
46+
"quote_attr_values": "always"
4747
}
4848
},
4949
{
@@ -64,32 +64,9 @@
6464
]
6565
]
6666
],
67-
"description": "quote_attr_values=true with irrelevant",
67+
"description": "quote_attr_values='always' with irrelevant",
6868
"options": {
69-
"quote_attr_values": true
70-
}
71-
},
72-
{
73-
"expected": [
74-
"<div class=\"foo\">"
75-
],
76-
"input": [
77-
[
78-
"StartTag",
79-
"http://www.w3.org/1999/xhtml",
80-
"div",
81-
[
82-
{
83-
"namespace": null,
84-
"name": "class",
85-
"value": "foo"
86-
}
87-
]
88-
]
89-
],
90-
"description": "non-minimized quote_attr_values=true",
91-
"options": {
92-
"quote_attr_values": true
69+
"quote_attr_values": "always"
9370
}
9471
},
9572
{

0 commit comments

Comments
 (0)