Skip to content

Commit

Permalink
Truncate extension of media items to 5 chars.
Browse files Browse the repository at this point in the history
That's the max length of the extensin
database field.

Fixes #609.

Signed-off-by: Thomas Hochstein <thh@inter.net>
  • Loading branch information
th-h committed Mar 25, 2020
1 parent 37a04ec commit ee62c48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Version 2.3.5-beta1 ()
------------------------------------------------------------------------

* Fix: Truncate extension of media items to 5 chars (which ist the
max length of the corresponding database field).

Version 2.3.4 (March 25th, 2020)
------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions include/functions_images.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,13 @@ function serendipity_uploadSecure($var, $strip_paths = true, $append_slash = fal
}
}

# truncate extensions to 5 chars
# 1) (\.[^.]{0,5}+) five chars after a dot are captured (possessively)
# 2) expression matches only if followed by anything that is no dot
# and has no / or \ at the end
# 3) if epxression matches, everything after the capture group is deleted
$var = preg_replace('@(\.[^.]{0,5}+)[^./\\\]*[^/\\\]{1,1}?$@', '$1', $var);

return $var;
}

Expand Down

0 comments on commit ee62c48

Please sign in to comment.