Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ivangrozni/3657801a41c7b0764e60c88750e0e0e4 to your computer and use it in GitHub Desktop.
Save ivangrozni/3657801a41c7b0764e60c88750e0e0e4 to your computer and use it in GitHub Desktop.
filename transliteration patch drupal
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