File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -459,9 +459,22 @@ def convert_entity(value):
459
459
if value [0 ] == "#" :
460
460
if len (value ) < 2 :
461
461
return None
462
+
462
463
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
465
478
466
479
return ENTITIES .get (value , None )
467
480
Original file line number Diff line number Diff line change 19
19
("&xx;" , "&xx;" ),
20
20
# Handles multiple entities in the same string
21
21
("this & that & that" , "this & that & that" ),
22
+ # Handles empty decimal and hex encoded code points
23
+ ("&#x;" , "&#x;" ),
24
+ ("&#;" , "&#;" ),
25
+ # Handles too high unicode points
26
+ ("�" , "�" ),
27
+ ("�" , "�" ),
28
+ ("�" , "�" ),
29
+ # Handles negative unicode points
30
+ ("&#-1;" , "&#-1;" ),
31
+ ("&#x-1;" , "&#x-1;" ),
22
32
],
23
33
)
24
34
def test_convert_entities (data , expected ):
You can’t perform that action at this time.
0 commit comments