Skip to content

Commit

Permalink
Merge pull request #2407 from fsprojects/fix_2405
Browse files Browse the repository at this point in the history
Paket failed with: String cannot be of zero length (#2405)
  • Loading branch information
matthid authored Jun 10, 2017
2 parents 81e5673 + 0ef46ba commit 38ee417
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Paket.Core/PaketConfigFiles/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type FrameworkDependentFile = {
Runtime : Rid option
}

type Library = {
type Library = {
/// Usually the file name without extension, use for sorting and stuff.
Name : string
Path : string
PathWithinPackage : string
Expand All @@ -27,7 +28,11 @@ type Library = {
module Library =
let ofFile (f:FrameworkDependentFile) =
let fi = FileInfo(normalizePath f.File.FullPath)
let name = fi.Name.Replace(fi.Extension, "")
// Extension can totally be an empty string, see https://github.com/fsprojects/Paket/issues/2405
let name =
let ext = fi.Extension
if String.IsNullOrEmpty ext then fi.Name
else fi.Name.Replace(ext, "")
{ Name = name; Path = f.File.FullPath; PathWithinPackage = f.File.PathWithinPackage }

type RuntimeLibrary = {
Expand Down
10 changes: 10 additions & 0 deletions tests/Paket.Tests/InstallModel/ProcessingSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ let fromLegacyList (prefix:string) l =
{ Paket.NuGet.UnparsedPackageFile.FullPath = i; Paket.NuGet.UnparsedPackageFile.PathWithinPackage = i.Substring(prefix.Length).Replace("\\", "/") }
else failwithf "Expected '%s' to start with '%s'" i prefix)

[<Test>]
let ``Library.ofFile should not crash on files without extension``() =
let frameworkDepFile = {
Path = { Name = ""; Platforms= [] }
File = { FullPath = Path.Combine(Path.GetTempPath(), "filewithoutext"); PathWithinPackage = "lib/net40" }
Runtime = None
}
let lib = Library.ofFile frameworkDepFile
lib.Name |> shouldEqual "filewithoutext"

[<Test>]
let ``should create empty model with net40, net45 ...``() =
let model = emptymodel.AddReferences ([ @"..\Rx-Main\lib\net40\Rx.dll"; @"..\Rx-Main\lib\net45\Rx.dll" ] |> fromLegacyList @"..\Rx-Main\")
Expand Down

0 comments on commit 38ee417

Please sign in to comment.