Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Malte L
gajim-plugins
Commits
214fb162
Commit
214fb162
authored
Dec 08, 2018
by
Philipp Hörist
Browse files
[preview] Fix problem with too long filenames
Fixes #365
parent
9bb2bc5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
url_image_preview/url_image_preview.py
View file @
214fb162
...
...
@@ -21,6 +21,7 @@ import binascii
import
logging
import
math
from
urllib.parse
import
urlparse
from
urllib.parse
import
unquote
from
io
import
BytesIO
import
shutil
from
functools
import
partial
...
...
@@ -174,7 +175,7 @@ class Base(object):
log
.
debug
(
'Url with text will not be displayed: %s'
,
real_text
)
return
urlparts
=
urlparse
(
real_text
)
urlparts
=
urlparse
(
unquote
(
real_text
)
)
if
not
self
.
_accept_uri
(
urlparts
,
real_text
,
additional_data
):
return
...
...
@@ -245,6 +246,12 @@ class Base(object):
filename
=
os
.
path
.
basename
(
urlparts
.
path
)
ext
=
os
.
path
.
splitext
(
filename
)[
1
]
name
=
os
.
path
.
splitext
(
filename
)[
0
]
if
len
(
name
)
>
90
:
# Many Filesystems have a limit on filename length
# Most have 255, some encrypted ones only 143
# We add around 50 chars for the hash,
# so the filename should not exceed 90
name
=
name
[:
90
]
namehash
=
hashlib
.
sha1
(
real_text
.
encode
(
'utf-8'
)).
hexdigest
()
newfilename
=
name
+
'_'
+
namehash
+
ext
thumbfilename
=
name
+
'_'
+
namehash
+
'_thumb_'
\
...
...
@@ -447,7 +454,7 @@ class Base(object):
log
.
error
(
'Could not download image for URL: %s'
,
url
)
return
urlparts
=
urlparse
(
url
)
urlparts
=
urlparse
(
unquote
(
url
)
)
filename
=
os
.
path
.
basename
(
urlparts
.
path
)
if
os
.
path
.
basename
(
filepath
).
startswith
(
'location_'
):
filename
=
os
.
path
.
basename
(
filepath
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment