From 5bf4abe647837a0f73198be368c7d1e95e014a51 Mon Sep 17 00:00:00 2001 From: Lucas Ou-Yang Date: Wed, 5 Sep 2018 00:28:37 -0700 Subject: [PATCH] Add `Article` constructor param sanitization guards --- newspaper/article.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/newspaper/article.py b/newspaper/article.py index dceb6ab1..e485a1dd 100644 --- a/newspaper/article.py +++ b/newspaper/article.py @@ -45,6 +45,12 @@ def __init__(self, url, title='', source_url='', config=None, **kwargs): """The **kwargs argument may be filled with config values, which is added into the config object """ + if isinstance(title, Configuration) or \ + isinstance(source_url, Configuration): + raise ArticleException( + 'Configuration object being passed incorrectly as title or ' + 'source_url! Please verify `Article`s __init__() fn.') + self.config = config or Configuration() self.config = extend_config(self.config, kwargs) @@ -343,7 +349,7 @@ def nlp(self): """ self.throw_if_not_downloaded_verbose() self.throw_if_not_parsed_verbose() - + nlp.load_stopwords(self.config.get_language()) text_keyws = list(nlp.keywords(self.text).keys()) title_keyws = list(nlp.keywords(self.title).keys()) @@ -526,7 +532,7 @@ def throw_if_not_downloaded_verbose(self): (self.download_exception_msg, self.url)) def throw_if_not_parsed_verbose(self): - """Parse `is_parsed` status -> log readable status + """Parse `is_parsed` status -> log readable status -> maybe throw ArticleException """ if not self.is_parsed: