Skip to content

Commit cd838c3

Browse files
authored
Merge pull request #579 from mozilla/validate-convert-entity-code-points
Validate convert entity code points
2 parents 90cb80b + 612b808 commit cd838c3

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

CHANGES

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
Bleach changes
22
==============
33

4+
Version 3.2.3 (January 26th, 2021)
5+
----------------------------------
6+
7+
**Security fixes**
8+
9+
None
10+
11+
**Features**
12+
13+
None
14+
15+
**Bug fixes**
16+
17+
* fix clean and linkify raising ValueErrors for certain inputs. Thank you @Google-Autofuzz.
18+
419
Version 3.2.2 (January 20th, 2021)
5-
------------------------------------
20+
----------------------------------
621

722
**Security fixes**
823

bleach/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919

2020
# yyyymmdd
21-
__releasedate__ = "20210120"
21+
__releasedate__ = "20210126"
2222
# x.y.z or x.y.z.dev0 -- semver
23-
__version__ = "3.2.2"
23+
__version__ = "3.2.3"
2424
VERSION = packaging.version.Version(__version__)
2525

2626

bleach/html5lib_shim.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,22 @@ def convert_entity(value):
459459
if value[0] == "#":
460460
if len(value) < 2:
461461
return None
462+
462463
if value[1] in ("x", "X"):
463-
return six.unichr(int(value[2:], 16))
464-
return six.unichr(int(value[1:], 10))
464+
# hex-encoded code point
465+
int_as_string, base = value[2:], 16
466+
else:
467+
# decimal code point
468+
int_as_string, base = value[1:], 10
469+
470+
if int_as_string == "":
471+
return None
472+
473+
code_point = int(int_as_string, base)
474+
if 0 < code_point < 0x110000:
475+
return six.unichr(code_point)
476+
else:
477+
return None
465478

466479
return ENTITIES.get(value, None)
467480

tests/test_html5lib_shim.py

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
("&xx;", "&xx;"),
2020
# Handles multiple entities in the same string
2121
("this &amp; that &amp; that", "this & that & that"),
22+
# Handles empty decimal and hex encoded code points
23+
("&#x;", "&#x;"),
24+
("&#;", "&#;"),
25+
# Handles too high unicode points
26+
("&#x110000;", "&#x110000;"),
27+
("&#x110111;", "&#x110111;"),
28+
("&#9277809;", "&#9277809;"),
29+
# Handles negative unicode points
30+
("&#-1;", "&#-1;"),
31+
("&#x-1;", "&#x-1;"),
2232
],
2333
)
2434
def test_convert_entities(data, expected):

tests_website/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="UTF-8">
5-
<title>Python Bleach 3.2.2</title>
5+
<title>Python Bleach 3.2.3</title>
66
<style>
77
textarea, iframe {
88
width: 95%;
@@ -20,7 +20,7 @@
2020
</style>
2121
</head>
2222
<body>
23-
<h2>Python Bleach 3.2.2</h2>
23+
<h2>Python Bleach 3.2.3</h2>
2424
<p>
2525
<a href="http://badge.fury.io/py/bleach"><img style="max-width:100%;" alt="pypi version" src="https://badge.fury.io/py/bleach.svg"></a>
2626
<a href="https://github.com/mozilla/bleach/actions?query=workflow%3ATest"><img style="max-width:100%;" alt="Build Status" src="https://github.com/mozilla/bleach/workflows/Test/badge.svg"></a>

0 commit comments

Comments
 (0)