Modify ↓
Opened on Apr 1, 2026 at 9:08:02 PM
#4086 closed Bug (Fixed)
Bug with IniReadSectionNames if file is coded with UTF-8-BOM
| Reported by: | anonymous | Owned by: | Jpm |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.18.0 | Severity: | None |
| Keywords: | Cc: |
Description (last modified by )
I have an ini-file that is formatted with UTF-8-BOM. If the file does not start with a linebreak, IniReadSectionNames does not retrieve the first section.
Local $sPathA, $sPathB, $sPathC, $sPathD, $hFile ; File A - UTF-8-BOM - No Leading LineBreak $sPathA = @DesktopDir & "\File_UTF-8-BOM_v1.ini" $hFile = FileOpen($sPathA, 2 + 8 + 128) FileWrite($hFile, "[SectionA]" & @CRLF & "Key=Value") FileClose($hFile) ; File B - UTF-8-BOM - Leading LineBreak $sPathB = @DesktopDir & "\File_UTF-8-BOM_v2.ini" $hFile = FileOpen($sPathB, 2 + 8 + 128) FileWrite($hFile, @CRLF & "[SectionB]" & @CRLF & "Key=Value") FileClose($hFile) ; File C - UTF-8 - No Leading LineBreak $sPathC = @DesktopDir & "\File_UTF-8_v1.ini" $hFile = FileOpen($sPathC, 2 + 8 + 256) FileWrite($hFile, "[SectionA]" & @CRLF & "Key=Value") FileClose($hFile) ; File D - UTF-8 - Leading LineBreak $sPathD = @DesktopDir & "\File_UTF-8_v2.ini" $hFile = FileOpen($sPathD, 2 + 8 + 256) FileWrite($hFile, @CRLF & "[SectionB]" & @CRLF & "Key=Value") FileClose($hFile) Local $aSectionA = IniReadSectionNames($sPathA) Local $aSectionB = IniReadSectionNames($sPathB) Local $aSectionC = IniReadSectionNames($sPathC) Local $aSectionD = IniReadSectionNames($sPathD) ConsoleWrite("$aSectionA" & @TAB & UBound($aSectionA) & @CRLF) ConsoleWrite("$aSectionB" & @TAB & UBound($aSectionB) & @CRLF) ConsoleWrite("$aSectionC" & @TAB & UBound($aSectionC) & @CRLF) ConsoleWrite("$aSectionD" & @TAB & UBound($aSectionD) & @CRLF) Exit
Attachments (0)
Change History (5)
comment:2 by , on Apr 1, 2026 at 10:23:44 PM
| Description: | modified (diff) |
|---|
comment:3 by , on Apr 1, 2026 at 11:09:17 PM
@JPM please also read:
also:
https://www.autoitscript.com/forum/topic/174335-file-encoding-problem/
comment:4 by , on Apr 4, 2026 at 10:48:17 AM
It is a bug in MS API used by AutoIt
It is true also for IniReadSection and IniRead
Those API was cerlainly created before UTF8 with BOM support
The only think I can do is to make a warning in the doc
Cheers
Local $sPathA, $sPathB, $sPathC, $sPathD, $hFile
Local $sSectionA = "SectionA"
Local $sSectionA1 = "SectionA1"
Local $sSectionB = "SectionB"
; File A - UTF-8-BOM - No Leading LineBreak
$sPathA = @ScriptDir & "\File_UTF-8-BOM_v1.ini"
$hFile = FileOpen($sPathA, 2 + 8 + 128)
FileWrite($hFile, "[" & $sSectionA & "]" & @CRLF & "KeyA=ValueA")
FileWrite($hFile, @CRLF & "[" & $sSectionA1 & "]" & @CRLF & "KeyA1=ValueA1")
FileClose($hFile)
;~ ; File B - UTF-8-BOM - Leading LineBreak
$sPathB = @ScriptDir & "\File_UTF-8-BOM_v2.ini"
$hFile = FileOpen($sPathB, 2 + 8 + 128)
FileWrite($hFile, @CRLF & "[" & $sSectionB & "]" & @CRLF & "KeyB=ValueB")
FileClose($hFile)
;~ ; File C - UTF-8 - No Leading LineBreak
$sPathC = @ScriptDir & "\File_UTF-8_v1.ini"
$hFile = FileOpen($sPathC, 2 + 8 + 256)
FileWrite($hFile, "[" & $sSectionA & "]" & @CRLF & "KeyC=ValueC")
FileClose($hFile)
;~ ; File D - UTF-8 - Leading LineBreak
$sPathD = @ScriptDir & "\File_UTF-8_v2.ini"
$hFile = FileOpen($sPathD, 2 + 8 + 256)
FileWrite($hFile, @CRLF & "[" & $sSectionB & "]" & @CRLF & "KeyD=ValueD")
FileClose($hFile)
Local $aSectionA = IniReadSectionNames($sPathA)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aSectionA = ' & $aSectionA & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
Local $aSectionB = IniReadSectionNames($sPathB)
Local $aSectionC = IniReadSectionNames($sPathC)
Local $aSectionD = IniReadSectionNames($sPathD)
ConsoleWrite("$aSectionA" & @TAB & UBound($aSectionA) & @CRLF)
ConsoleWrite("$aSectionB" & @TAB & UBound($aSectionB) & @CRLF)
ConsoleWrite("$aSectionC" & @TAB & UBound($aSectionC) & @CRLF)
ConsoleWrite("$aSectionD" & @TAB & UBound($aSectionD) & @CRLF)
Local $aKeyA = IniReadSection($sPathA, $sSectionA)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aKeyA = ' & $aKeyA & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
Local $aKeyA1 = IniReadSection($sPathA, $sSectionA1)
Local $aKeyB = IniReadSection($sPathB, $sSectionB)
Local $aKeyC = IniReadSection($sPathC, $sSectionA)
Local $aKeyD = IniReadSection($sPathD, $sSectionB)
ConsoleWrite("$aKeyA" & @TAB & UBound($aKeyA) & @CRLF)
ConsoleWrite("$aKeyA1" & @TAB & UBound($aKeyA1) & @CRLF)
ConsoleWrite("$aKeyB" & @TAB & UBound($aKeyB) & @CRLF)
ConsoleWrite("$aKeyC" & @TAB & UBound($aKeyC) & @CRLF)
ConsoleWrite("$aKeyD" & @TAB & UBound($aKeyD) & @CRLF)
Local $sValueA = IniRead($sPathA, $sSectionA, "KeyA", "???")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sValueA = ' & $sValueA & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
Local $sValueA1 = IniRead($sPathA, $sSectionA1, "KeyA1", "???")
Local $sValueB = IniRead($sPathB, $sSectionB, "KeyB", "???")
Local $sValueC = IniRead($sPathC, $sSectionA, "KeyC", "???")
Local $sValueD = IniRead($sPathD, $sSectionB, "KeyD", "???")
ConsoleWrite("$sValueA" & @TAB & $sValueA & @CRLF)
ConsoleWrite("$sValueA1" & @TAB & $sValueA1 & @CRLF)
ConsoleWrite("$sValueB" & @TAB & $sValueB & @CRLF)
ConsoleWrite("$sValueC" & @TAB & $sValueC & @CRLF)
ConsoleWrite("$sValueD" & @TAB & $sValueD & @CRLF)
Exit
comment:5 by , on Apr 15, 2026 at 3:21:36 PM
| Owner: | set to |
|---|---|
| Resolution: | → Fixed |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

see discussion at https://www.autoitscript.com/forum/topic/213616-bug-with-inireadsectionnames-if-file-is-coded-with-utf-8-bom/#comment-1551213