Skip to content

Commit

Permalink
Strip img and a tags when checking phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-daniels committed Jun 7, 2015
1 parent 9bcec25 commit 25386d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions findspam.py
Expand Up @@ -155,6 +155,9 @@ def test_post(title, body, user_name, site, is_answer, body_is_summary):
if rule['stripcodeblocks']:
body_to_check = regex.sub("<pre>.*?</pre>", "", body, flags=regex.DOTALL)
body_to_check = regex.sub("<code>.*?</code>", "", body_to_check, flags=regex.DOTALL)
if rule['reason'] == 'Phone number detected':
body_to_check = regex.sub("<img[^>]+>", "", body_to_check)
body_to_check = regex.sub("<a[^>]+>", "", body_to_check)
if rule['all'] != (site in rule['sites']):
matched_title = regex.compile(rule['regex'], regex.UNICODE).findall(title)
matched_username = regex.compile(rule['regex'], regex.UNICODE).findall(user_name)
Expand Down
5 changes: 4 additions & 1 deletion test/test_regexes.py
Expand Up @@ -65,7 +65,10 @@
(u'Как рандомно получать числа 1 и 2?', 'Body here', u'Сашка', 'ru.stackoverflow.com', False, False),
('Should not be caught: http://example.com', '', '', 'drupal.stackexchange.com', False, False),
('Should not be caught: https://www.example.com', '', '', 'drupal.stackexchange.com', False, False),
('Should not be caught: something@example.com', '', '', 'drupal.stackexchange.com', False, False)
('Should not be caught: something@example.com', '', '', 'drupal.stackexchange.com', False, False),
('Title here', '<img src="http://example.com/11111111111.jpg" alt="my image">', '', 'stackoverflow.com', False, False),
('Title here', '<img src="http://example.com/11111111111111.jpg" alt="my image" />', '', 'stackoverflow.com', False, False),
('Title here', '<a href="http://example.com/11111111111111.html">page</a>', '', 'stackoverflow.com', False, False)
])
def test_regexes(title, body, username, site, body_is_summary, match):
# If we want to test answers separately, this should be changed
Expand Down

0 comments on commit 25386d7

Please sign in to comment.