Last active
March 16, 2022 13:05
-
-
Save ivangrozni/3657801a41c7b0764e60c88750e0e0e4 to your computer and use it in GitHub Desktop.
filename transliteration patch drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/FilenamePostprocessor.php b/src/FilenamePostprocessor.php | |
index 6f1e45b7634a26cf6c78a9dae573fda77dd79845..d2b5451eebbde31a7abb9dc689d9b73c2a85ad5d 100644 | |
--- a/src/FilenamePostprocessor.php | |
+++ b/src/FilenamePostprocessor.php | |
@@ -70,8 +70,31 @@ class FilenamePostprocessor { | |
$filename = str_replace('-_', '_', $filename); | |
$filename = str_replace('_.', '.', $filename); | |
$filename = str_replace('-.', '.', $filename); | |
+ $filename = $this->removeDoubleFileEnding($filename); | |
return $filename; | |
} | |
+ /** | |
+ * Remove duplicate file suffix. | |
+ * | |
+ * @param string $filename | |
+ * Filename. | |
+ * | |
+ * @return string | |
+ * Filename with duplicate suffix removed. | |
+ */ | |
+ protected function removeDoubleFileEnding(string $filename) { | |
+ $exploded_filename = explode('.', $filename); | |
+ for ($i = count($exploded_filename) - 1; $i >= 0; $i -= 1) { | |
+ if (!isset($last)) { | |
+ $last = $exploded_filename[$i]; | |
+ } | |
+ elseif ($exploded_filename[$i] == $last) { | |
+ unset($exploded_filename[$i]); | |
+ } | |
+ } | |
+ return implode('.', $exploded_filename); | |
+ } | |
+ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment