Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/common/preview.py
    ... ... @@ -21,6 +21,7 @@
    21 21
     
    
    22 22
     import logging
    
    23 23
     import os
    
    24
    +import re
    
    24 25
     from pathlib import Path
    
    25 26
     from urllib.parse import urlparse
    
    26 27
     from urllib.parse import ParseResult
    
    ... ... @@ -33,6 +34,7 @@
    33 34
     
    
    34 35
     from gajim.common import app
    
    35 36
     from gajim.common import configpaths
    
    37
    +from gajim.common import regex
    
    36 38
     from gajim.common.const import MIME_TYPES
    
    37 39
     from gajim.common.helpers import AdditionalDataDict
    
    38 40
     from gajim.common.helpers import load_file_async
    
    ... ... @@ -53,6 +55,8 @@
    53 55
     
    
    54 56
     log = logging.getLogger('gajim.c.preview')
    
    55 57
     
    
    58
    +IRI_RX = re.compile(regex.IRI)
    
    59
    +
    
    56 60
     PREVIEWABLE_MIME_TYPES = get_previewable_mime_types()
    
    57 61
     mime_types = set(MIME_TYPES)
    
    58 62
     # Merge both: if it’s a previewable image, it should be allowed
    
    ... ... @@ -333,8 +337,9 @@ def _accept_uri(urlparts: ParseResult,
    333 337
         def is_previewable(self,
    
    334 338
                            text: str,
    
    335 339
                            additional_data: AdditionalDataDict) -> bool:
    
    336
    -        if len(text.split(' ')) > 1:
    
    337
    -            # urlparse doesn't recognise spaces as URL delimiter
    
    340
    +        if not IRI_RX.fullmatch(text):
    
    341
    +            # urlparse removes whitespace (and who knows what else) from URLs,
    
    342
    +            # so can't be used for validation.
    
    338 343
                 return False
    
    339 344
     
    
    340 345
             uri = text