Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decode #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion htmlentities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def encode(source):


def decode(source):
for entitie in re.findall('&(?:[a-z][a-z0-9]+);', source):
for entitie in re.findall('&(?:[a-z][a-z0-9]+);', source, re.I):
entitie = entitie.replace('&', '')
entitie = entitie.replace(';', '')
source = source.replace('&%s;' % entitie, unichr(name2codepoint[entitie]))
Expand Down
10 changes: 10 additions & 0 deletions tests/test_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ def test_should_decode_basic_entities(self):
def test_should_decode_utf8_accents(self):
self.assertEqual(u'é', htmlentities.decode('é'))
self.assertEqual(u'ê', htmlentities.decode('ê'))

def test_decode_complex_unicode_text(self):
"""Validates the encoding and decoding of sample text"""
text = u"Übergroße Äpfel mit Würmern"

# result string: Übergroße Äpfel mit Würmern

result = htmlentities.decode(htmlentities.encode(text))

self.assertEquals(result, text)