From ca8e9fb800914a6fb7f1b932662a7da02f611d80 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 12 Apr 2019 09:28:57 +0530 Subject: [PATCH] bugdown: Make the youtube URL regex slightly easier to read. --- zerver/lib/bugdown/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index 56295c6e22..dee06f3e5f 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -679,9 +679,12 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor): # Youtube video id extraction regular expression from http://pastebin.com/KyKAFv1s # Slightly modified to support URLs of the form youtu.be/ # If it matches, match.group(2) is the video id. - youtube_re = r'^((?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)' + \ - r'(?:(?:(?:v|embed)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))?)' + \ - r'?([0-9A-Za-z_-]+)(?(1).+)?$' + schema_re = r'(?:https?://)' + host_re = r'(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)' + param_re = r'(?:(?:(?:v|embed)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))' + id_re = r'([0-9A-Za-z_-]+)' + youtube_re = r'^({schema_re}?{host_re}{param_re}?)?{id_re}(?(1).+)?$' + youtube_re = youtube_re.format(schema_re=schema_re, host_re=host_re, id_re=id_re, param_re=param_re) match = re.match(youtube_re, url) if match is None: return None