Forced Preferences utf8 BOM

Post bugreports for the Windows version here
Sergey
User
User
Posts: 65
Joined: Wed Jan 12, 2022 2:41 pm

Forced Preferences utf8 BOM

Post by Sergey »

Hi,
when I want to change value my ini file becomes with BOM+CRLF (5 bytes: EF BB BF 0D 0A) again :|

Code: Select all

#test_filename = "test_file.ini"

If CreatePreferences(#test_filename, #PB_Preference_NoBOM)
	PreferenceGroup("main")
	WritePreferenceString("key", "value1")
	ClosePreferences()
EndIf

MessageRequester("", "File created, size: " + Str(FileSize(#test_filename))); 22 bytes

If OpenPreferences(#test_filename)
	PreferenceGroup("main")
	WritePreferenceString("key", "value2")
	ClosePreferences()
EndIf

MessageRequester("", "File size: " + Str(FileSize(#test_filename))); 27 bytes[/code]
Last edited by Sergey on Wed Nov 19, 2025 6:02 pm, edited 1 time in total.
Axolotl
Addict
Addict
Posts: 893
Joined: Wed Dec 31, 2008 3:36 pm

Re: Forced Preferences utf8 BOM

Post by Axolotl »

Yeah, good observation.
I am pretty sure that this is not a bug, its a feature.

And this has been discussed several times. Ultimately, it's a design decision made by FRED.
And don't forget that prefs is (precisely) not ini. It just happens to use the same format.

BTW: I would still think it would be good if that were changed (at some point)...... especially the CRLF at the end. :)

Important Note: Don't scold me, I'm just repeating what I learned here.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Sergey
User
User
Posts: 65
Joined: Wed Jan 12, 2022 2:41 pm

Re: Forced Preferences utf8 BOM

Post by Sergey »

Axolotl wrote: Wed Nov 19, 2025 11:46 am ... especially the CRLF at the end. :)
Thank Axolotl for answer
I agree with you to remove CRLF

I think that the meaning of #PB_Preference_NoBOM in CreatePreferences is lost if it appears independently
You need to check OpenPreferences for the presence of BOM and if it was present write it or not write it if it was not there
User avatar
kenmo
Addict
Addict
Posts: 2068
Joined: Tue Dec 23, 2003 3:54 am

Re: Forced Preferences utf8 BOM

Post by kenmo »

Not sure if this is a "bug" or a "feature request" but I agree, OpenPreferences should preserve whether there's a BOM, or else maybe allow the NoBOM flag like CreatePreferences().

In the meantime a procedure can be used to remove it. Read file to buffer, check for BOM + CRLF, if found write the file contents back minus those initial bytes.
Post Reply