diff --git a/rivescript/parser.py b/rivescript/parser.py index 93973f5..951c39d 100644 --- a/rivescript/parser.py +++ b/rivescript/parser.py @@ -539,9 +539,9 @@ def check_syntax(self, cmd, line): if search: return "Topics should be lowercased and contain only numbers and letters" elif parts[0] == "object": - search = re.search(RE.name_syntax, line) + search = re.search(RE.obj_syntax, line) # Upper case is allowed if search: - return "Objects can only contain numbers and letters" # TODO Acceptance of uppercase letter? + return "Objects can only contain numbers and letters" elif cmd == '+' or cmd == '%' or cmd == '@': # + Trigger, % Previous, @ Redirect # This one is strict. The triggers are to be run through the regexp engine, diff --git a/rivescript/regexp.py b/rivescript/regexp.py index 45ce8e3..5df6dc0 100644 --- a/rivescript/regexp.py +++ b/rivescript/regexp.py @@ -24,6 +24,7 @@ class RE(object): array = re.compile(r'\@(.+?)\b') def_syntax = re.compile(r'^.+(?:\s+.+|)\s*=\s*.+?$') name_syntax = re.compile(r'[^a-z0-9_\-\s]') + obj_syntax = re.compile(r'[^A-Za-z0-9_\-\s]') utf8_trig = re.compile(r'[A-Z\\.]') trig_syntax = re.compile(r'[^a-z0-9(\|)\[\]*_#@{}<>=\s]') cond_syntax = re.compile(r'^.+?\s*(?:==|eq|!=|ne|<>|<|<=|>|>=)\s*.+?=>.+?$') diff --git a/tests/test_format_message.py b/tests/test_format_message.py index 47fb68f..b21e625 100644 --- a/tests/test_format_message.py +++ b/tests/test_format_message.py @@ -32,22 +32,28 @@ def test_format_triggers(self): def test_invalid_character_raise_exception(self): self.assertRaises(Exception, self.new, """ - + $hello - - hi - """) # This test passes with `match`, which only check at the beginning + + $hello + - hi + """) # This test passes with `match`, which only check at the beginning self.assertRaises(Exception, self.new, """ - + hello$ - - hi - """) # This test does not pass because the beginning is good, no $ + + hello$ + - hi + """) # This test does not pass because the beginning is good, no $ self.assertRaises(Exception, self.new, """ - > topic Greetings - + hello - - hi - topic Greetings + + hello + - hi + object hash %perl - my ($rs, $args) = @_; - my $method = shift @{$args}; - object hash %perl + my ($rs, $args) = @_; + my $method = shift @{$args}; + object hash Perl + my ($rs, $args) = @_; + my $method = shift @{$args}; +