Skip to content
Prev Previous commit
Next Next commit
Disallows space between ! and file pattern to exclude
  • Loading branch information
devboy committed Jun 22, 2015
commit dea44fd69f6e1a266b0a7bec064704b3d7135ff5
10 changes: 4 additions & 6 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ module internal TemplateFile =

let private fromReg = Regex("from (?<from>.*)", RegexOptions.Compiled)
let private toReg = Regex("to (?<to>.*)", RegexOptions.Compiled)

let private fileExclusionChar = '!'
let private isFileExclusion (l:string) = l.Trim().StartsWith(fileExclusionChar.ToString())
let private isExclude = Regex("\s*!\S", RegexOptions.Compiled)

let private getFiles (map : Map<string, string>) =
Map.tryFind "files" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map (Array.filter (fun l -> l |> isFileExclusion |> not))
|> Option.map (Array.filter (fun l -> l |> isExclude.IsMatch |> not))
|> Option.map
(Seq.map
(fun (line:string) ->
Expand All @@ -245,10 +243,10 @@ module internal TemplateFile =
let private getFileExcludes (map : Map<string, string>) =
Map.tryFind "files" map
|> Option.map (fun d -> d.Split '\n')
|> Option.map (Array.filter isFileExclusion)
|> Option.map (Array.filter isExclude.IsMatch)
|> Option.map
(Seq.map
(fun (line:string) -> line.Trim().TrimStart(fileExclusionChar)))
(fun (line:string) -> line.Trim().TrimStart('!')))
|> Option.map List.ofSeq
|> fun x -> defaultArg x []

Expand Down
25 changes: 25 additions & 0 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,31 @@ files
| [x] -> x |> shouldEqual "excludeDir"
| _ -> Assert.Fail()

[<Test>]
let ``disallow the space to avoid ambiguity in exclusion file pattern``() =
let text = """type file
id My.Thing
authors Bob McBob
description
A longer description
on two lines.
version
1.0
files
someDir
anotherDir ==> someLib
! excludeDir
"""
let sut =
TemplateFile.Parse("file1.template", None, strToStream text)
|> returnOrFail
|> function
| CompleteInfo (_, opt)
| ProjectInfo (_, opt) -> opt
match sut.FilesExcluded with
| [] -> Assert.Pass()
| _ -> Assert.Fail()

[<Literal>]
let ProjectType1 = """type project
"""
Expand Down