Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6879f6a

Browse files
author
Greg Guthe
committed
1 parent90cb80b commit6879f6a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

‎bleach/html5lib_shim.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,22 @@ def convert_entity(value):
459459
ifvalue[0]=="#":
460460
iflen(value)<2:
461461
returnNone
462+
462463
ifvalue[1]in ("x","X"):
463-
returnsix.unichr(int(value[2:],16))
464-
returnsix.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+
ifint_as_string=="":
471+
returnNone
472+
473+
code_point=int(int_as_string,base)
474+
if0<code_point<0x110000:
475+
returnsix.unichr(code_point)
476+
else:
477+
returnNone
465478

466479
returnENTITIES.get(value,None)
467480

‎tests/test_html5lib_shim.py‎

Lines changed: 10 additions & 0 deletions
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
deftest_convert_entities(data,expected):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp