Skip to content

Commit

Permalink
fix: add word boudary around anonymized term
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Aug 8, 2018
1 parent 7eee5e3 commit a1e2e41
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions server.py
Expand Up @@ -86,7 +86,7 @@ def create_flask_application(self):
application.jinja_env.add_extension('jinja2.ext.do')

@application.template_filter('remove_terms', )
def remove_terms(content, repository_configuration):
def remove_terms(content, repository_configuration, word_boundaries=True):
"""
remove the blacklisted terms from the content
:param content: the content to anonymize
Expand All @@ -100,7 +100,10 @@ def remove_terms(content, repository_configuration):
"%s/repository/%s" % (self.public_url, repository_configuration["id"]), content)
content = re.compile(repo, re.IGNORECASE).sub("%s/repository/%s" % (self.public_url, repository_configuration["id"]), content)
for term in repository_configuration['terms']:
content = re.compile(term, re.IGNORECASE).sub("XXX", content)
if word_boundaries:
content = re.compile(r'\b%s\b' % term, re.IGNORECASE).sub("XXX", content)
else:
content = re.compile(term, re.IGNORECASE).sub("XXX", content)
return content

@application.template_filter('file_render', )
Expand Down

0 comments on commit a1e2e41

Please sign in to comment.