Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape file names #960

Merged
merged 1 commit into from
Aug 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Paket.Core/NupkgWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
let path = DirectoryInfo(p).FullName
exclusions |> List.exists (fun f -> f path)

let ensureValidName (target: string) =
Uri.EscapeDataString(target.Replace("\\", "/")).Replace("%5C", "/")
|> fun s -> if s.StartsWith("./") then s.Remove(0,2) else s

let addEntry path writerF =
if entries.Contains(path) then () else
entries.Add path |> ignore
Expand All @@ -241,9 +245,7 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
zipFile.CreateEntryFromFile(source,path) |> ignore

let ensureValidTargetName (target:string) =
let target =
target.Replace(" ", "%20").Replace("\\", "/")
|> fun s -> if s.StartsWith("./") then s.Remove(0,2) else s
let target = ensureValidName target

match target with
| t when t.EndsWith("/") -> t
Expand All @@ -258,7 +260,8 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
for file in Directory.EnumerateFiles(source,"*.*",SearchOption.TopDirectoryOnly) do
if not <| isExcluded file then
let fi = FileInfo file
let path = Path.Combine(target,fi.Name)
let fileName = ensureValidName fi.Name
let path = Path.Combine(target,fileName)

addEntryFromFile path fi.FullName

Expand All @@ -276,7 +279,8 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
if File.Exists source then
if not <| isExcluded source then
let fi = FileInfo(source)
let path = Path.Combine(targetFileName,fi.Name)
let fileName = ensureValidName fi.Name
let path = Path.Combine(targetFileName,fileName)
addEntryFromFile path source
else
failwithf "Could not find source file %s" source
Expand Down