summaryrefslogtreecommitdiff
path: root/addons/website_slides
diff options
context:
space:
mode:
authorJulien Banken <jbn@odoo.com>2021-05-10 07:36:51 +0000
committerJulien Banken <jbn@odoo.com>2021-05-12 12:32:22 +0000
commit9572e2ab46962149372af45efb35b91f6e64f268 (patch)
tree4e6d2011643adffe192b95385f259cbe05f485c2 /addons/website_slides
parent5ea2fcbecf572be24af9b2aac76de9e5d5709d2c (diff)
[FIX] slides: Verifying the returned value of re.search before accessing the capture groups.
The `search` function of the `re` package can return `None` if the provided string does not match with the provided pattern (https://docs.python.org/3/library/re.html#re.Pattern.search). On the `_parse_youtube_document` function of the `slide.slide` model, we are directly accessing the capture groups from the returned value of the `search` function without checking that the returned value is actually a 'match' object. As a result, an exception can be throw if there is no match as, in that case, the `search` function will return `None` and the `group` function will not be defined on `None`. To avoid throwing an exception, we will check that the returned value of the `search` function is not `None` before accessing the capture groups via the `group` function. LINKS Task id: 2525007 closes odoo/odoo#70743 X-original-commit: 575a524474fe8866cc71b3befc6bbbde8d73075e Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/website_slides')
-rw-r--r--addons/website_slides/models/slide_slide.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py
index 9a440b2a8bb..2b68a0db332 100644
--- a/addons/website_slides/models/slide_slide.py
+++ b/addons/website_slides/models/slide_slide.py
@@ -780,9 +780,10 @@ class Slide(models.Model):
youtube_duration = youtube_values.get('contentDetails', {}).get('duration')
if youtube_duration:
parsed_duration = re.search(r'^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$', youtube_duration)
- values['completion_time'] = (int(parsed_duration.group(1) or 0)) + \
- (int(parsed_duration.group(2) or 0) / 60) + \
- (int(parsed_duration.group(3) or 0) / 3600)
+ if parsed_duration:
+ values['completion_time'] = (int(parsed_duration.group(1) or 0)) + \
+ (int(parsed_duration.group(2) or 0) / 60) + \
+ (int(parsed_duration.group(3) or 0) / 3600)
if youtube_values.get('snippet'):
snippet = youtube_values['snippet']