diff --git a/content.py b/content.py index dfbabd338..84fffeac9 100644 --- a/content.py +++ b/content.py @@ -380,10 +380,15 @@ def validHashTag(hashtag: str) -> bool: # TODO: this may need to be an international character set validChars = set('0123456789' + 'abcdefghijklmnopqrstuvwxyz' + - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + '¡¿ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæĀā' + + 'ÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĖėĒē' + + 'ĜĝĢģĞğĤĥÌìÍíÎîÏïıĪīĮįĴĵĶķ' + + 'ĹĺĻļŁłĽľĿŀÑñŃńŇňŅņÖöÒòÓóÔôÕõŐőØøŒœ' + + 'ŔŕŘřẞߌśŜŝŞşŠšȘșŤťŢţÞþȚțÜüÙùÚúÛûŰűŨũŲųŮůŪū' + + 'ŴŵÝýŸÿŶŷŹźŽžŻż') if set(hashtag).issubset(validChars): - if '&' not in hashtag and '#' not in hashtag: - return True + return True return False diff --git a/tests.py b/tests.py index 83ecabca7..f5549bfbd 100644 --- a/tests.py +++ b/tests.py @@ -76,6 +76,7 @@ from inbox import jsonPostAllowsComments from inbox import validInbox from inbox import validInboxFilenames from categories import guessHashtagCategory +from content import validHashTag from content import htmlReplaceEmailQuote from content import htmlReplaceQuoteMarks from content import dangerousCSS @@ -3088,9 +3089,22 @@ def testPrepareHtmlPostNickname(): assert result == expectedHtml +def testValidHashTag(): + print('testValidHashTag') + assert validHashTag('ThisIsValid') + assert validHashTag('ThisIsValid12345') + assert validHashTag('ThisIsVälid') + assert not validHashTag('ThisIsNotValid!') + assert not validHashTag('#ThisIsAlsoNotValid') + assert not validHashTag('ThisIsAlso&NotValid') + assert not validHashTag('ThisIsAlsoNotValid"') + assert not validHashTag('This=IsAlsoNotValid"') + + def runAllTests(): print('Running tests...') testFunctions() + testValidHashTag() testPrepareHtmlPostNickname() testDomainHandling() testMastoApi()