filename:join breaks Windows UNC paths

Evgeny Khirin khirin@REDACTED
Sun Jul 18 08:13:40 CEST 2010


Hello,

"Normalize" feature of filename:join breaks Windows UNC paths:
filename:join("//host/share", "file") returns "/host/share/file" on Windows instead "//host/share/file".

Patch below fixes the problem.

Regards,
Evgeny.

------------------- patch --------------------------------
diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl
index 01c06e4..8da54ef 100644
--- a/lib/stdlib/src/filename.erl
+++ b/lib/stdlib/src/filename.erl
@@ -316,6 +316,10 @@ join(Name1, Name2) when is_atom(Name2) ->
 %% It is the responsibility of the caller to ensure that RelativeName
 %% is relative.

+join1([$/, $/ | Rest], RelativeName, [], win32) -> [$/, $/ | join1(Rest, RelativeName, [], win32)];
+join1([$/, $\\ | Rest], RelativeName, [], win32) -> [$/, $/ | join1(Rest, RelativeName, [], win32)];
+join1([$\\, $/ | Rest], RelativeName, [], win32) -> [$/, $/ | join1(Rest, RelativeName, [], win32)];
+join1([$\\, $\\ | Rest], RelativeName, [], win32) -> [$/, $/ | join1(Rest, RelativeName, [], win32)];
 join1([UcLetter, $:|Rest], RelativeName, [], win32)
 when is_integer(UcLetter), UcLetter >= $A, UcLetter =< $Z ->
     join1(Rest, RelativeName, [$:, UcLetter+$a-$A], win32);
------------------- patch --------------------------------


More information about the erlang-patches mailing list