@@ -243,10 +243,11 @@ function (array $matches) use ($varDefinitions) {
243243 }
244244 }
245245
246- if (!$ isModifiedModel
246+ if ((!empty ($ relative ) && $ relative !== '/ ' )
247+ && !$ isModifiedModel
247248 && $ serviceName !== 's3 '
248249 ) {
249- $ relative = $ this ->prependPath ( $ relative , $ path );
250+ $ this ->normalizePath ( $ path );
250251 }
251252
252253 // If endpoint has path, remove leading '/' to preserve URI resolution.
@@ -310,31 +311,17 @@ private function getVarDefinitions($command, $args)
310311 }
311312
312313 /**
313- * If non-empty path with at least one segment present, compare
314- * with relative and prepend if starting segments are not duplicated
314+ * Appends trailing slash to non-empty paths with at least one segment
315+ * to ensure proper URI resolution
315316 *
316- * @param string $relative
317317 * @param string $path
318318 *
319- * @return string
319+ * @return void
320320 */
321- private function prependPath (string $ relative , string $ path ): string
321+ private function normalizePath (string $ path ): void
322322 {
323- if (empty ($ relative ) || $ relative === '/ '
324- || empty ($ path ) || $ path === '/ '
325- ) {
326- return $ relative ;
323+ if (!empty ($ path ) && $ path !== '/ ' && substr ($ path , -1 ) !== '/ ' ) {
324+ $ this ->endpoint = $ this ->endpoint ->withPath ($ path . '/ ' );
327325 }
328-
329- $ normalizedPath = rtrim ($ path , '/ ' );
330- $ normalizedRelative = ltrim ($ relative , '/ ' );
331-
332- // Check if $relative starts with $path
333- if (strpos ($ normalizedRelative , ltrim ($ normalizedPath , '/ ' )) === 0 ) {
334- // $relative already starts with $path, return $relative
335- return $ relative ;
336- }
337-
338- return $ normalizedPath . '/ ' . $ normalizedRelative ;
339326 }
340327}
0 commit comments