Skip to content

Commit

Permalink
- fixed UTF8 BOM issue when parsing properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
stackh34p committed Nov 11, 2017
1 parent 016d4d0 commit 52b91f4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/core/primitives/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ open System.Runtime.InteropServices
[<assembly: ComVisible(false)>]
[<assembly: Guid("f46be8de-7918-48af-b19f-4d33a4fd6d79")>]

[<assembly: AssemblyVersion("0.2.0.38")>]
[<assembly: AssemblyFileVersion("0.2.0.38")>]
[<assembly: AssemblyVersion("0.2.0.47")>]
[<assembly: AssemblyFileVersion("0.2.0.47")>]

do
()
8 changes: 6 additions & 2 deletions src/core/primitives/JavaProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ type JavaProperties(file: FileInfo, encoding: Encoding) as self =
do
match null2opt file with
| Some f ->
use stream = f.OpenRead()
_props.Load(stream, match null2opt encoding with Some e -> e | None -> Encoding.UTF8)
let e = match null2opt encoding with Some e -> e | None -> Encoding.UTF8
// detect and remove any UTF8 BOM mark before parsing the properties to prevent a corrupted read
let mutable fc = File.ReadAllText(f.FullName, e)
if (fc.StartsWith("\uFEFF", StringComparison.Ordinal)) then fc <- fc.Substring(1)
use stream = new MemoryStream(e.GetBytes(fc.ToCharArray()))
_props.Load(stream, e)
| None -> nullArg "file"
member __.Keys with get() = _props.Keys.Cast<string>()
member __.Item with get(key) =
Expand Down
2 changes: 1 addition & 1 deletion src/core/primitives/Mason.Primitives.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Compile Include="Sdk\IMasonModule.fs" />
<Compile Include="Sdk\AbstractMasonModule.fs" />
<Compile Include="Sdk\ModuleChain.fs" />
<Compile Include="Sdk\AbstractSettings.fs" />
<Compile Include="Sdk\AbstractMasonSettings.fs" />
<None Include="Script.fsx" />
<None Include="paket-update.sh" />
<None Include="paket.sh" />
Expand Down
25 changes: 17 additions & 8 deletions src/core/primitives/MasonConfiguration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ open System.IO
module MasonConfiguration =

[<Literal>]
let DefaultConfigFileName: string = "mason.properties";
let DefaultConfigFileName: string = "mason.properties"
[<Literal>]
let SolutionFilePattern: string = "*.sln";
let SolutionFilePattern: string = "*.sln"

[<Literal>]
let ContextPropertyProjectFileName = "mason.context.project-file";
let ContextPropertyProjectFileName = "mason.context.project-file"
[<Literal>]
let ContextPropertySolutionDirName = "mason.context.solution-dir";
let ContextPropertySolutionDirName = "mason.context.solution-dir"
[<Literal>]
let ContextPropertyLocationName = "mason.context.location";
let ContextPropertyLocationName = "mason.context.location"
[<Literal>]
let ContextPropertyFileName = "mason.context.config"

let strNonEmpty(str: string) =
match null2opt str with
Expand All @@ -35,13 +37,20 @@ module MasonConfiguration =
contextConfig.[ContextPropertyLocationName] <- loc

let mutable locationDir = DirectoryInfo(loc)
let projectSpecificConfigs = locationDir.GetFiles(String.Format("{0}.{1}", projectName, buildConfigFileName), SearchOption.TopDirectoryOnly)
if (projectSpecificConfigs.Length = 1) then configs <- Array.append configs [|JavaProperties(projectSpecificConfigs.[0])|]
let projectConfigFileName = String.Format("{0}.{1}", projectName, buildConfigFileName);
let projectSpecificConfigs = locationDir.GetFiles(projectConfigFileName, SearchOption.TopDirectoryOnly)
if (projectSpecificConfigs.Length = 1) then
configs <- Array.append configs [|JavaProperties(projectSpecificConfigs.[0])|]
contextConfig.[ContextPropertyFileName] <- projectConfigFileName

let mutable shouldTraverse: bool = true
while (shouldTraverse) do
let defaultConfigs = locationDir.GetFiles(buildConfigFileName, SearchOption.TopDirectoryOnly)
if (defaultConfigs.Length = 1) then configs <- Array.append configs [|JavaProperties(defaultConfigs.[0])|]
if (defaultConfigs.Length = 1) then
configs <- Array.append configs [|JavaProperties(defaultConfigs.[0])|]
match null2opt contextConfig.[ContextPropertyFileName] with
| Some _ -> ()
| _ -> contextConfig.[ContextPropertyFileName] <- buildConfigFileName

let solutionFiles = locationDir.GetFiles(SolutionFilePattern, SearchOption.TopDirectoryOnly)
if (solutionFiles.Length > 0) then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ open Mason
type AbstractMasonSettings(properties: IMasonProperties) =
[<Literal>]
let RequiredPropertyMissingMessageFormat: string = "Required property '{0}' is not defined.";
member __.Location with get() = properties.[MasonConfiguration.ContextPropertyLocationName]
member __.Location with get() = __.GetRequiredProperty(MasonConfiguration.ContextPropertyLocationName)
member __.ProjectFile with get() = properties.[MasonConfiguration.ContextPropertyProjectFileName]
member __.SolutionDir with get() = properties.[MasonConfiguration.ContextPropertySolutionDirName]
member __.ConfigFile with get() = properties.[MasonConfiguration.ContextPropertyFileName]
member __.GetRequiredProperty key:string =
match null2opt key with
| Some k ->
Expand Down
2 changes: 1 addition & 1 deletion src/core/primitives/mason.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id = "Mason.Primitives"
description = "Mason Primitives library"
version.revision = 39
version.revision = 48
guid = "f46be8de-7918-48af-b19f-4d33a4fd6d79"

mason-packager.output.location = "../../../dist/"

0 comments on commit 52b91f4

Please sign in to comment.