From 1133a800eee12bf866c51389ff2b8fe09a8ea5a5 Mon Sep 17 00:00:00 2001 From: Aysel Afsar Date: Mon, 23 Dec 2024 23:21:05 -0500 Subject: [PATCH] #136 Encode url path segments (#139) --- lib/Controller/DisplayController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Controller/DisplayController.php b/lib/Controller/DisplayController.php index c83f6ae..47251fa 100755 --- a/lib/Controller/DisplayController.php +++ b/lib/Controller/DisplayController.php @@ -178,7 +178,7 @@ private function encodeUrlPathSegments($url) { $segments = explode('/', $url); foreach ($segments as $index => $segment) { - if ($index > 2 && $segment !== '') { + if ($segment !== '') { $segments[$index] = rawurlencode($segment); } } @@ -193,17 +193,17 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi $fileUrlPath = ''; if ($isPublic) { if ($singlePublicFileDownload) { - $urlParamFiles = substr($dicomFilePath, strrpos($dicomFilePath, '/') + 1); - $fileUrlPath = $downloadUrlPrefix.'/'.$urlParamFiles; + $urlParamFiles = $this->encodeUrlPathSegments(substr($dicomFilePath, strrpos($dicomFilePath, '/') + 1)); + $fileUrlPath = $this->encodeUrlPathSegments($downloadUrlPrefix.'/'.$urlParamFiles); } else { - $urlParamPath = substr($dicomFilePath, 0, strrpos($dicomFilePath, '/')); - $urlParamFiles = substr($dicomFilePath, strrpos($dicomFilePath, '/') + 1); + $urlParamPath = $this->encodeUrlPathSegments(substr($dicomFilePath, 0, strrpos($dicomFilePath, '/'))); + $urlParamFiles = $this->encodeUrlPathSegments(substr($dicomFilePath, strrpos($dicomFilePath, '/') + 1)); $fileUrlPath = $downloadUrlPrefix.'?path='.$urlParamPath.'&files='.$urlParamFiles; } } else if ($currentUserPathToFile != null) { - $fileUrlPath = $downloadUrlPrefix.strstr($dicomFilePath, $currentUserPathToFile); + $fileUrlPath = $this->encodeUrlPathSegments($downloadUrlPrefix.strstr($dicomFilePath, $currentUserPathToFile)); } else { - $fileUrlPath = $downloadUrlPrefix.$dicomFilePath; + $fileUrlPath = $this->encodeUrlPathSegments($downloadUrlPrefix.$dicomFilePath); } $fileUrl = $this->urlGenerator->getAbsoluteURL($fileUrlPath); @@ -352,7 +352,7 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi 'WindowWidth' => $WindowWidth ? explode('\\', $WindowWidth)[0] : $WindowWidth, 'SeriesDate' => $SeriesDate, ), - 'url' => 'dicomweb:'.$this->encodeUrlPathSegments($fileUrl), + 'url' => 'dicomweb:'.$fileUrl, ); array_push($dicomJson['studies'][$studyIndex]['series'][$seriesIndex]['instances'], $instance); $dicomJson['studies'][$studyIndex]['NumInstances']++;