Skip to content

Conversation

@htdinh
Copy link
Contributor

@htdinh htdinh commented Feb 15, 2017

replace regex match by regex search for detection of invalid characters in the middle of the string.

@htdinh htdinh changed the title Issue 82 … Issue #82 solution Feb 15, 2017
@htdinh
Copy link
Contributor Author

htdinh commented Feb 24, 2017

@kirsle Can you please take a review on this?

return "Objects can only contain numbers and letters"
search = re.search(RE.name_syntax, line)
if search:
return "Objects can only contain numbers and letters" # TODO Acceptance of uppercase letter?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems safe enough to me to allow uppercase letters in object names. You may need to add a new syntax regexp to regexp.py to support that, like r'[^A-Za-z0-9_\-\s]'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this accordingly.

my ($rs, $args) = @_;
my $method = shift @{$args};
<object
""") # Test for character violation in object, no %
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how all these blocks of code are formatted. The indentations are all over the place.

Maybe something like this instead:

    def test_invalid_character_raise_exception(self):
        # This test passes with `match`, which only check at the beginning
        self.assertRaises(Exception, self.new, """
            + $hello
            - hi
        """)

        # etc for all the other tests.

@kirsle
Copy link
Member

kirsle commented Feb 24, 2017

Just to be sure: this change makes the $ character invalid for triggers right? I'd want it to raise a RiveScript syntax error at parse time.

$ is a special metacharacter in regexps and I don't have a custom use for it in RiveScript like I do for some of the other metacharacters (e.g. [ and ]), so I'd want it to raise an error instead of silently doing the wrong thing when the regexp gets executed.

@kirsle kirsle merged commit ab3b255 into aichaos:master Feb 24, 2017
@htdinh
Copy link
Contributor Author

htdinh commented Feb 24, 2017

Yes, $ is one of many invalid characters. The valid sets is ( | ) [ ] * _ # @ { } < > = and it is check at https://github.com/aichaos/rivescript-python/blob/master/rivescript/parser.py#L594. I may made a mistake putting a review there. I don't know how to quote the code to here. You can close that if not an appropriate place.

@htdinh
Copy link
Contributor Author

htdinh commented Mar 23, 2017

@kirsle Do you plan to include this fix in the new release anytime soon? I find this bug fix is urgent because check_syntax checks the validity of the trigger. For example, $1.00 has already been detected as incorrect format but 1.00$ slipped through the check because the string doesn't start with invalid character.

@kirsle
Copy link
Member

kirsle commented Mar 23, 2017

@Dinh-Hung-Tu I just published v1.14.6 to PyPI so you can update to get this fix. 😄

@htdinh
Copy link
Contributor Author

htdinh commented Mar 25, 2017

Thanks @kirsle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants