Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Merge pull request #653 from willkg/1175123-fixes
Browse files Browse the repository at this point in the history
[bug 1175123] Fix keyword matching
  • Loading branch information
willkg committed Aug 26, 2015
2 parents 912dcde + 938e8d2 commit 3daef19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fjord/suggest/providers/trigger/models.py
Expand Up @@ -54,8 +54,10 @@ def _escape(utext):
u'|'.join(keywords) +
u')'
)
regex = ur'((?:^|\s)' + middle + ur'(?:\s|$))'
return re.compile(regex, re.LOCALE | re.IGNORECASE | re.UNICODE)
# Note: Can't use \b here because we need to be able to find
# arbitrary strings--not just alphanumeric ones.
regex = ur'(?:^|\W)' + middle + ur'(?:\W|$)'
return re.compile(regex, re.IGNORECASE | re.UNICODE)


class TriggerRule(ModelBase):
Expand Down
2 changes: 2 additions & 0 deletions fjord/suggest/providers/trigger/tests/test_models.py
Expand Up @@ -84,6 +84,8 @@ def test_match_keywords(self):
([u'\xca'], u'abcd \xca abcd', True),
([u'my-cat'], u'my-cat has fleas', True),
([u'(my cat)'], u'(my cat) has fleas', True),
([u'cat'], u'i love my cat!', True),
([u'cat'], u'(cat)', True),
]
for tr_keywords, description, expected in tests:
tr = TriggerRuleFactory(keywords=tr_keywords)
Expand Down

0 comments on commit 3daef19

Please sign in to comment.