Unexpected behavior - IniRead

Issue #40 closed
Winter Laite created an issue

kstests.ini:

[SECTION1]
Primate = Baboon
[SECTION2]
Primate = Bonobo

Code for first test::

Value := IniRead("kstests.ini", "SECTION1", "Primate", "Monkey")
MsgBox("The primate is a " Value, "Who's in the zoo?")

AHK reports that ‘[T]he primate is a Baboon’, correctly.

Keysharp reports the default: ‘The primate is a Monkey’.

The following error message is reported:

Uncaught Keysharp exception:

Message: The operation completed successfully.

What: Keysharp.Core.Ini.IniRead()

if the following code is used for testing (i.e., default omitted):

Value := IniRead("kstests.ini", "SECTION1", "Primate")
MsgBox("The primate is a " Value, "Who's in the zoo?")

But with AHK this runs correctly and reports the Baboon to be in residence.

As a sanity check, the following .INI file was used:

[sectionone]
keyval=theval
#Comment 1
[sectiontwo]
groupkey1=groupval1
#Comment 2
groupkey2=groupval2
#Comment 3
groupkey3=groupval3

[sectionthree]
groupkey11=groupval11
groupkey22=groupval22
groupkey33=groupval33
#Comment 4

Taken from the Keysharp code.

Test code:

Value := IniRead(".\testini.ini", "sectiontwo", "groupkey1", "did not find")
MsgBox("The value is " Value)

This works in both AHK and Keysharp, reporting “groupkey1” correctly.

My issue, which well may not be a bug, is that the first .INI file and test code do not work in Keysharp.

This also works in Keysharp:

Value := IniRead(".\testini.ini", "sectiontwo", "groupkey1")
MsgBox("The value is " Value)

although the default is NOT present.

This leads me to believe this is not a bug, just unexpected or different behavior. I will try limiting section names to lowercase and report back. Thanks for your patience.

Comments (7)

  1. Winter Laite reporter

    The first .INI file was changed as follows:

    [sectionone]
    primate=Baboon
    [sectiontwo]
    primate2=Bonobo
    

    Test code that works in both AHK and Keysharp:

    Value := IniRead(".\kstests.ini", "sectionone", "primate")
    MsgBox("The primate is a " Value, "Who's in the zoo?")
    

    No default value, yet correct result in both.

    If this is a bug, it appears to be related to uppercase in section names (possibly elsewhere, will check).

  2. Winter Laite reporter

    It appears that an INI file written with ‘IniWrite’ does not suffer from the case problems. For now, I will create them with Keysharp and ‘IniWrite’.

  3. Matt Feemster repo owner

    The problem was that the files were not being processed in a case insensitive manner.

    I’ve fixed it so that section1, Section1 and SECTION1 all would work.

    Please test.

  4. Winter Laite reporter

    Tested with various case combinations, including mixed case. Fixed! Please mark as resolved and close. Thanks!

  5. Log in to comment