From 33e5937d8d8096d61861ba06d55529c4a27e98fd Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Fri, 29 Sep 2023 08:58:33 -0400 Subject: [PATCH] Fix hyphen-in-path bug in ImportLokaliseCommand. (#3130) --- .../Language/ImportLokaliseCommand.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/module/VuFindConsole/src/VuFindConsole/Command/Language/ImportLokaliseCommand.php b/module/VuFindConsole/src/VuFindConsole/Command/Language/ImportLokaliseCommand.php index 1faa26c4a3f..6a98ac19f7d 100644 --- a/module/VuFindConsole/src/VuFindConsole/Command/Language/ImportLokaliseCommand.php +++ b/module/VuFindConsole/src/VuFindConsole/Command/Language/ImportLokaliseCommand.php @@ -138,15 +138,20 @@ protected function matchTargetFiles(string $sourceDir, string $targetDir, array if (!file_exists($targetFile)) { $parts = explode('-', $targetFile); if (count($parts) > 1) { - array_pop($parts); - $revisedTargetFile = implode('-', $parts) . '.ini'; - $matchingSourceFile = preg_replace( - '/^' . preg_quote($targetDir, '/') . '/', - $sourceDir, - $revisedTargetFile - ); - if (!in_array($matchingSourceFile, $sourceFiles)) { - $targetFile = $revisedTargetFile; + $lastPart = array_pop($parts); + // If there's a slash in the last part, this means there's a hyphen + // in a directory name somewhere. We should only process further if + // the hyphen is in the FILENAME. + if (!str_contains($lastPart, '/')) { + $revisedTargetFile = implode('-', $parts) . '.ini'; + $matchingSourceFile = preg_replace( + '/^' . preg_quote($targetDir, '/') . '/', + $sourceDir, + $revisedTargetFile + ); + if (!in_array($matchingSourceFile, $sourceFiles)) { + $targetFile = $revisedTargetFile; + } } } }