Last active
December 17, 2018 14:05
-
-
Save munsiwoo/65f6780ef4ac75f4786ae0535cb4dc7e to your computer and use it in GitHub Desktop.
HTML Entities en/decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.parse | |
# made by munsiwoo | |
# <img src=# onerror="alert(1)"> | |
def htmlentities_encode(string, url_encoding=0) : | |
result = str() | |
for st in string : | |
result += '&#'+str(ord(st))+';' | |
if url_encoding : | |
return urllib.parse.quote(result) | |
return result | |
def htmlentities_decode(string) : | |
string = string.replace('&#', ' ') | |
string = string.replace(';', '').strip() | |
result = str() | |
for st in string.split(' ') : | |
result += chr(int(st)) | |
return result | |
print(htmlentities_encode('abcd')) | |
print(htmlentities_encode('abcd', 1)) | |
print(htmlentities_decode('abcd')) | |
''' | |
abcd | |
%26%2397%3B%26%2398%3B%26%2399%3B%26%23100%3B | |
abcd | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment