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

Fix for quoted parameter parsing #311

Merged
merged 1 commit into from
Oct 29, 2014
Merged
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ module DependenciesFileParser =
with
| _ -> failwithf "could not parse version range \"%s\"" text

let parseDependencyLine (line:string) =
let rec parseDepLine start acc =
if start >= line.Length then acc
else
match line.[start] with
| ' ' -> parseDepLine (start+1) acc
| '"' ->
match line.IndexOf('"', start+1) with
| -1 -> failwithf "Unclosed quote in line '%s'" line
| ind -> parseDepLine (ind+1) (line.Substring(start+1, ind-start-1)::acc)
| _ ->
match line.IndexOf(' ', start+1) with
| -1 -> line.Substring(start)::acc
| ind -> parseDepLine (ind+1) (line.Substring(start, ind-start)::acc)
parseDepLine 0 []
|> List.rev
|> List.toArray

let private (|Remote|Package|Blank|ReferencesMode|OmitContent|SourceFile|) (line:string) =
match line.Trim() with
Expand Down Expand Up @@ -99,7 +116,7 @@ module DependenciesFileParser =
| trimmed when trimmed.StartsWith "references" -> ReferencesMode(trimmed.Replace("references","").Trim() = "strict")
| trimmed when trimmed.StartsWith "content" -> OmitContent(trimmed.Replace("content","").Trim() = "none")
| trimmed when trimmed.StartsWith "github" ->
let parts = trimmed.Replace("\"", "").Trim().Split([|' '|],StringSplitOptions.RemoveEmptyEntries)
let parts = parseDependencyLine trimmed
let getParts (projectSpec:string) =
match projectSpec.Split [|':'; '/'|] with
| [| owner; project |] -> owner, project, None
Expand Down
16 changes: 16 additions & 0 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ let ``should read github source file from config without quotes``() =
Name = "src/app/FAKE/FileWithCommit.fs"
Commit = Some "bla123zxc" } ]

[<Test>]
let ``should read github source file from config with quotes``() =
let config = """github fsharp/FAKE:master "src/app/FAKE/Cli.fs"
github fsharp/FAKE:bla123zxc "src/app/FAKE/FileWith Space.fs" """
let dependencies = DependenciesFile.FromCode(config)
dependencies.RemoteFiles
|> shouldEqual
[ { Owner = "fsharp"
Project = "FAKE"
Name = "src/app/FAKE/Cli.fs"
Commit = Some "master" }
{ Owner = "fsharp"
Project = "FAKE"
Name = "src/app/FAKE/FileWith Space.fs"
Commit = Some "bla123zxc" } ]

[<Test>]
let ``should read github source files withou sha1``() =
let config = """github fsharp/FAKE src/app/FAKE/Cli.fs
Expand Down