Skip to content

Commit

Permalink
Parse file specs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
inosik committed Jan 28, 2017
1 parent 6d3cefd commit cfe15bf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,22 @@ module LockFileParser =
| GitHubLink | GistLink ->
match currentGroup.RemoteUrl |> Option.map(fun s -> s.Split '/') with
| Some [| owner; project |] ->
let pieces =
if details.Contains '"' then
let pathInfo =
match details.IndexOf ('"', 1) with
| idx when idx >= 0 -> Some (details.Substring (1, idx - 1), idx)
| _ -> None
match pathInfo with
| Some (path, pathEndIdx) ->
let commitAndAuthKey = details.Substring(pathEndIdx + 1).Split(' ')
Array.append [| path |] commitAndAuthKey
| None -> Array.empty
else
details.Split ' '

let path, commit, authKey =
match details.Split ' ' with
match pieces with
| [| filePath; commit; authKey |] -> filePath, commit |> removeBrackets, (Some authKey)
| [| filePath; commit |] -> filePath, commit |> removeBrackets, None
| _ -> failwith "invalid file source details."
Expand Down
22 changes: 22 additions & 0 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,25 @@ let ``should parse local git lock file with build and no specs``() =
lockFile.Head.SourceFiles.Head.Commit |> shouldEqual "2942d23fcb13a2574b635194203aed7610b21903"
lockFile.Head.SourceFiles.Head.Project |> shouldEqual "nupkgtest"
lockFile.Head.SourceFiles.Head.Command |> shouldEqual (Some "build.cmd Test")

let lockFileWithFilesContainingSpaces = """
GITHUB
remote: owner/repo
specs:
"file 1.fs" (7623fc13439f0e60bd05c1ed3b5f6dcb937fe468)"""

[<Test>]
let ``should parse lock file with spaces in file names``() =
let lockFile = LockFileParser.Parse (toLines lockFileWithFilesContainingSpaces)
let sourceFiles = List.rev lockFile.Head.SourceFiles
sourceFiles|> shouldEqual
[ { Owner = "owner"
Project = "repo"
Name = "file 1.fs"
Origin = ModuleResolver.Origin.GitHubLink
Dependencies = Set.empty
Commit = "7623fc13439f0e60bd05c1ed3b5f6dcb937fe468"
Command = None
OperatingSystemRestriction = None
PackagePath = None
AuthKey = None } ]

0 comments on commit cfe15bf

Please sign in to comment.