@@ -481,10 +481,10 @@ defmodule URI do
481
481
raise ArgumentError , "you must merge onto an absolute URI"
482
482
end
483
483
def merge ( _base , % URI { scheme: rel_scheme } = rel ) when rel_scheme != nil do
484
- rel
484
+ % { rel | path: remove_dot_segments_from_path ( rel . path ) }
485
485
end
486
486
def merge ( base , % URI { authority: authority } = rel ) when authority != nil do
487
- % { rel | scheme: base . scheme }
487
+ % { rel | scheme: base . scheme , path: remove_dot_segments_from_path ( rel . path ) }
488
488
end
489
489
def merge ( % URI { } = base , % URI { path: rel_path } = rel ) when rel_path in [ "" , nil ] do
490
490
% { base | query: rel . query || base . query , fragment: rel . fragment }
@@ -500,7 +500,7 @@ defmodule URI do
500
500
defp merge_paths ( nil , rel_path ) ,
501
501
do: merge_paths ( "/" , rel_path )
502
502
defp merge_paths ( _ , "/" <> _ = rel_path ) ,
503
- do: rel_path
503
+ do: remove_dot_segments_from_path ( rel_path )
504
504
defp merge_paths ( base_path , rel_path ) do
505
505
[ _ | base_segments ] = path_to_segments ( base_path )
506
506
path_to_segments ( rel_path )
@@ -509,6 +509,17 @@ defmodule URI do
509
509
|> Enum . join ( "/" )
510
510
end
511
511
512
+ defp remove_dot_segments_from_path ( nil ) do
513
+ nil
514
+ end
515
+
516
+ defp remove_dot_segments_from_path ( path ) do
517
+ path
518
+ |> path_to_segments ( )
519
+ |> remove_dot_segments ( [ ] )
520
+ |> Enum . join ( "/" )
521
+ end
522
+
512
523
defp remove_dot_segments ( [ ] , [ head , ".." | acc ] ) ,
513
524
do: remove_dot_segments ( [ ] , [ head | acc ] )
514
525
defp remove_dot_segments ( [ ] , acc ) ,
0 commit comments