From ad87596e37eb6cac52ee0ee3474e4e843420ff1c Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 4 Feb 2021 21:21:00 -0500 Subject: [PATCH] Better error handling for revision IDs --- copyvios/api.py | 1 + copyvios/checker.py | 10 ++++++++-- templates/index.mako | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/copyvios/api.py b/copyvios/api.py index ffec124..4da06fd 100644 --- a/copyvios/api.py +++ b/copyvios/api.py @@ -11,6 +11,7 @@ __all__ = ["format_api_error", "handle_api_request"] _CHECK_ERRORS = { "no search method": "Either 'use_engine' or 'use_links' must be true", + "bad oldid": "The revision ID is invalid", "no URL": "The parameter 'url' is required for URL comparisons", "bad URI": "The given URI scheme is unsupported", "no data": "No text could be found in the given URL (note that only HTML " diff --git a/copyvios/checker.py b/copyvios/checker.py index 4e25eeb..6bd8aad 100644 --- a/copyvios/checker.py +++ b/copyvios/checker.py @@ -3,6 +3,7 @@ from datetime import datetime, timedelta from hashlib import sha256 from logging import getLogger +import re from urlparse import urlparse from earwigbot import exceptions @@ -28,11 +29,16 @@ def do_check(query=None): if not query: query = Query() if query.lang: - query.lang = query.orig_lang = query.lang.lower() + query.lang = query.orig_lang = query.lang.strip().lower() if "::" in query.lang: query.lang, query.name = query.lang.split("::", 1) if query.project: - query.project = query.project.lower() + query.project = query.project.strip().lower() + if query.oldid: + query.oldid = query.oldid.strip().lstrip("0") + if not re.match(r"^\d+$", query.oldid): + query.error = "bad oldid" + return query.submitted = query.project and query.lang and (query.title or query.oldid) if query.submitted: diff --git a/templates/index.mako b/templates/index.mako index fa5bc28..44586c8 100644 --- a/templates/index.mako +++ b/templates/index.mako @@ -19,6 +19,8 @@ Unknown action: ${query.action | h}. % elif query.error == "no search method": No copyvio search methods were selected. A check can only be made using the search engine, links present in the page, Turnitin, or some combination of these. + % elif query.error == "bad oldid": + The revision ID ${query.oldid | h} is invalid. It should be an integer. % elif query.error == "no URL": URL comparison mode requires a URL to be entered. Enter one in the text box below, or choose copyvio search mode to look for content similar to the article elsewhere on the web. % elif query.error == "bad URI": @@ -215,7 +217,7 @@ <% attrib = get_attribution_info(query.site, query.page) %> % if attrib:
- This article contains an attribution template: {{${attrib[0] | h}}}. Please verify that any potential copyvios are not from properly attributed sources. + This article contains an attribution template: {{${attrib[0] | h}}}. Please verify that any potential copyvios are not from properly attributed sources.
% endif