Modify

#4086 new Bug

Bug with IniReadSectionNames if file is coded with UTF-8-BOM

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: 3.3.18.0 Severity: None
Keywords: Cc:

Description (last modified by mLipok)

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 (3)

comment:2 by mLipok, on Apr 1, 2026 at 10:23:44 PM

Description: modified (diff)

Modify Ticket

Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.