Skip to content

Commit

Permalink
Escape file names
Browse files Browse the repository at this point in the history
Characters such as " " and "%" in file names would break when installing
the package with nuget
  • Loading branch information
will14smith committed Aug 5, 2015
1 parent 5c64801 commit 731801d
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit 731801d

Please sign in to comment.