Skip to content

Commit ec133c2

Browse files
author
hungtu
committed
aichaos#37 Fix unicode handling
1 parent 303d607 commit ec133c2

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

rivescript/brain.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ def reply_regexp(self, user, regexp):
501501
self.format_message(history[type][0]))
502502
# TODO: the Perl version doesn't do just <input>/<reply> in trigs!
503503

504-
return re.compile(r'^' + regexp.lower() + r'$')
504+
if self.utf8:
505+
return re.compile(r'^' + regexp.lower() + r'$', re.UNICODE)
506+
else:
507+
return re.compile(r'^' + regexp.lower() + r'$')
505508

506509
def do_expand_array(self, array_name, depth=0):
507510
"""Do recurrent array expansion, returning a set of keywords.

tests/test_unicode.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ def test_unicode_punctuation(self):
8282
self.rs.unicode_punctuation = re.compile(r'xxx')
8383
self.reply("Hello bot", "Hello human!")
8484
self.reply("Hello, bot!", RS_ERR_MATCH)
85+
86+
def test_unicode_with_optionals(self):
87+
templates = ["({})", "[{}]", "[*] ({}) [*]", "[*] [{}] [*]"] # Test both alternatives and optionals
88+
trigger_text = "überrasch mich|empfiehl mir was|empfehl mir was|was gibts neues für mich|empfehlung"
89+
90+
for template in templates:
91+
test_template = template.format(trigger_text)
92+
self.new("""
93+
+ {}
94+
- recommendation
95+
""".format(test_template), utf8=True)
96+
97+
self.reply("überrasch mich", "recommendation")
98+
self.reply("überrasch", '[ERR: No Reply Matched]')
99+
self.reply("empfiehl mir was", "recommendation")
100+
self.reply("was gibts neues für mich", "recommendation")

0 commit comments

Comments
 (0)