Skip to content

Commit

Permalink
aichaos#37 Fix unicode handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hungtu committed Sep 21, 2017
1 parent 303d607 commit ec133c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rivescript/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,10 @@ def reply_regexp(self, user, regexp):
self.format_message(history[type][0]))
# TODO: the Perl version doesn't do just <input>/<reply> in trigs!

return re.compile(r'^' + regexp.lower() + r'$')
if self.utf8:
return re.compile(r'^' + regexp.lower() + r'$', re.UNICODE)
else:
return re.compile(r'^' + regexp.lower() + r'$')

def do_expand_array(self, array_name, depth=0):
"""Do recurrent array expansion, returning a set of keywords.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,19 @@ def test_unicode_punctuation(self):
self.rs.unicode_punctuation = re.compile(r'xxx')
self.reply("Hello bot", "Hello human!")
self.reply("Hello, bot!", RS_ERR_MATCH)

def test_unicode_with_optionals(self):
templates = ["({})", "[{}]", "[*] ({}) [*]", "[*] [{}] [*]"] # Test both alternatives and optionals
trigger_text = "überrasch mich|empfiehl mir was|empfehl mir was|was gibts neues für mich|empfehlung"

for template in templates:
test_template = template.format(trigger_text)
self.new("""
+ {}
- recommendation
""".format(test_template), utf8=True)

self.reply("überrasch mich", "recommendation")
self.reply("überrasch", '[ERR: No Reply Matched]')
self.reply("empfiehl mir was", "recommendation")
self.reply("was gibts neues für mich", "recommendation")

0 comments on commit ec133c2

Please sign in to comment.