Skip to content

Commit

Permalink
Fix #1692
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed May 19, 2018
1 parent d5d3a55 commit 0b49266
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* FAKE5: Global dotnet cli-tool `fake-cli` - https://github.com/fsharp/FAKE/pull/1932
Install via `dotnet tool install fake-cli -g`
* BUGFIX: Some issues when running latest `dotnet cli` via the Fake.DotNet.Cli module.
* BUGFIX: Fake.Core.Xml changed DOCTYPE - https://github.com/fsharp/FAKE/issues/1692

## 5.0.0-rc014 - 2018-05-20

Expand Down
10 changes: 10 additions & 0 deletions src/app/Fake.Core.Xml/Xml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ let private load (fileName:string) (doc:XmlDocument) =
use fs = File.OpenRead(fileName)
doc.Load fs
let private save (fileName:string) (doc:XmlDocument) =
// https://stackoverflow.com/questions/284394/net-xmldocument-why-doctype-changes-after-save
// https://stackoverflow.com/a/16451790
// https://github.com/fsharp/FAKE/issues/1692

let docType = doc.DocumentType
if not (isNull docType) then
if System.String.IsNullOrWhiteSpace docType.InternalSubset then
let documentTypeWithNullInternalSubset =
doc.CreateDocumentType(docType.Name, docType.PublicId, docType.SystemId, null)
docType.ParentNode.ReplaceChild(documentTypeWithNullInternalSubset, docType) |> ignore
use fs = File.Open(fileName, FileMode.Truncate, FileAccess.Write)
doc.Save fs

Expand Down
2 changes: 2 additions & 0 deletions src/test/Fake.Core.UnitTests/Fake.Core.UnitTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectReference Include="..\..\app\Fake.Core.SemVer\Fake.Core.SemVer.fsproj" />
<ProjectReference Include="..\..\app\Fake.Core.Target\Fake.Core.Target.fsproj" />
<ProjectReference Include="..\..\app\Fake.Core.ReleaseNotes\Fake.Core.ReleaseNotes.fsproj" />
<ProjectReference Include="..\..\app\Fake.Core.Xml\Fake.Core.Xml.fsproj" />
<ProjectReference Include="..\..\app\Fake.Runtime\Fake.Runtime.fsproj" />
</ItemGroup>
<ItemGroup>
Expand All @@ -25,6 +26,7 @@
<Compile Include="Fake.Core.Process.fs" />
<Compile Include="Fake.Core.Target.fs" />
<Compile Include="Fake.Core.ReleaseNotes.fs" />
<Compile Include="Fake.Core.Xml.fs" />
<Compile Include="Fake.Runtime.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions src/test/Fake.Core.UnitTests/Fake.Core.Xml.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Fake.Core.XmlTests

open System.IO
open Fake.Core
open Fake.DotNet
open Expecto
open Expecto.Flip

[<Tests>]
let tests =
testList "Fake.Core.Xml.Tests" [
testCase "Xml issue #1692" <| fun _ ->
let original = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>foo</string>
</dict>
</plist>"""
let expected = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>whateva</string>
</dict>
</plist>"""
let tmpFile = Path.GetTempFileName()
try
File.WriteAllText(tmpFile, original)
let bundleIdentifier = "whateva"
Xml.pokeInnerText tmpFile "plist/dict/key[text()='CFBundleIdentifier']/following-sibling::string" bundleIdentifier
let actual = File.ReadAllText tmpFile
Expect.equal "expected same xml" expected actual
finally
File.Delete(tmpFile)
]

0 comments on commit 0b49266

Please sign in to comment.