mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
reimplemented unescapeHtmlString to fix bug, added test cases
This commit is contained in:
parent
f9caf8b01b
commit
791162d433
@ -4021,17 +4021,26 @@ def histogramDict(l):
|
|||||||
def unescapeHtmlString(s):
|
def unescapeHtmlString(s):
|
||||||
# converts %## to corresponding character
|
# converts %## to corresponding character
|
||||||
# replaces '+' with ' '
|
# replaces '+' with ' '
|
||||||
while 1:
|
result = ''
|
||||||
try:
|
i = 0
|
||||||
i = s.index('%')
|
while i < len(s):
|
||||||
except:
|
char = s[i]
|
||||||
break
|
if char == '+':
|
||||||
lastCharIndex = len(s)-1
|
char = ' '
|
||||||
if i <= lastCharIndex-2:
|
elif char == '%':
|
||||||
num = eval('0x' + s[i+1:i+3])
|
if i < (len(s)-2):
|
||||||
s = s[:i] + chr(num) + s[i+3:]
|
num = eval('0x' + s[i+1:i+3])
|
||||||
s = s.replace('+', ' ')
|
char = chr(num)
|
||||||
return s
|
i += 2
|
||||||
|
i += 1
|
||||||
|
result += char
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __debug__:
|
||||||
|
assert unescapeHtmlString('asdf') == 'asdf'
|
||||||
|
assert unescapeHtmlString('as+df') == 'as df'
|
||||||
|
assert unescapeHtmlString('as%32df') == 'as2df'
|
||||||
|
assert unescapeHtmlString('asdf%32') == 'asdf2'
|
||||||
|
|
||||||
import __builtin__
|
import __builtin__
|
||||||
__builtin__.Functor = Functor
|
__builtin__.Functor = Functor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user