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

Don't change BOM for existing project files - fixes #2271 #2575

Merged
merged 1 commit into from
Aug 17, 2017

Conversation

TeaDrivenDev
Copy link
Contributor

As mentioned in #2271, some project files have a BOM (created by VS), others don't (from Ionide/Forge), so to know what "unchanged" means, we have to probe the original file and set the encoding for writing the XML file accordingly. We only consider UTF-8 because it seems safe to assume all project files will have that.

@@ -1180,11 1180,20 @@ module ProjectFile =


let save forceTouch project =
let hasUtf8Bom fileName =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go in another place? I kept it as a local function because it's only used here.

if File.Exists fileName then
use fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)
let bomBuffer = Array.zeroCreate 4
fs.Read(bomBuffer, 0, 4) |> ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this save?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.Read(bomBuffer, 0, 4)
what happens if it's 3 bytes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the next line is most likely false or undefined.

Comparing the result with 4 would definitely make future readers more happy ;)

@TeaDrivenDev
Copy link
Contributor Author

Updated with a better way to get the bytes to compare against.

@forki What did you mean earlier with "What happens if it's 3 bytes"? If the file is shorter than what we're trying to read, FileStream.Read() will take what it can get and return the number of bytes as an integer (which we ignore). That would leave us with a byte array that is not equal to the expected BOM, and we would decide to write the project file without a BOM.

@forki
Copy link
Member

forki commented Aug 17, 2017

thx!

@forki forki merged commit 9150a63 into fsprojects:master Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants