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

Quotation marks being added to certain INI values despite never being explicitly modified? #352

Open
1 task done
SuperFromND opened this issue Jul 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@SuperFromND
Copy link

SuperFromND commented Jul 27, 2024

Version

v1.67.0

Describe the bug

Let me preface this by apologizing in advance if this is more of a problem with my lack of experience with Go/this library than an actual bug, still pretty new to using both.

I'm attempting to make a program that adds one line to an INI-formatted file under a specific section and then saves it without touching the rest of the file. Yet whenever I do this, go-ini seems to erroneously add extra quotation marks around certain values despite me never telling the library to touch those lines.

To reproduce

The function in question causing the problem, as lifted from my Iguana project (linked in case you need full source code instead of just a snippet):

func patch_def(def string) {
    fmt.Println("Patching DEF file...")

    file_data, err := os.ReadFile(def)
    check_error(err)

    parsed_ini, err := ini.LoadSources(ini.LoadOptions{AllowNonUniqueSections: true, IgnoreInlineComment: true, SkipUnrecognizableLines: true}, file_data)
    check_error(err)

    for s := range parsed_ini.Sections() {
        var sect_name = parsed_ini.Sections()[s].Name()

        // find the Files section
        if strings.EqualFold(sect_name, "Files") {
            for k := range parsed_ini.Sections()[s].Keys() {
                var key_name = parsed_ini.Sections()[s].KeyStrings()[k]

                if strings.EqualFold(key_name, "cmd") {
                    // get the value of cmd
                    cmd_value := parsed_ini.Sections()[s].Key(key_name).String()

                    // strip the cmd value to just the path, and then add the output filename to it
                    dat_value := filepath.Join(filepath.Dir(cmd_value), output_file)

                    // add our new path to the INI and save it
                    parsed_ini.Sections()[s].NewKey("movelist", dat_value)
                    parsed_ini.SaveTo(def)
                    return
                }
            }
        }
    }

    fmt.Println("Iguana wasn't able to find a command file from this DEF. No changes have been made.")
    return
}

Setting IgnoreInlineComment: true to false does not create these extra quotation marks, but it also forces every single inline comment to be on a new line, which I don't want.

Expected behavior

The INI file I'm testing that's giving these problems (if you're testing/attempting to reproduce this issue with the full program source linked above, you must give this file a .def extension):
skapon_def.txt

What I want to do is simply add a line under the [Files] section, without touching anything else in the file (comments, other key-value pairs, etc.):

;-----必要なファイルの設定------------------------------------------

[Files]
Cmd      = skapon.cmd		;入力コマンド定義ファイルの登録
Cns      = skapon.cns		;基本ステータス情報ファイルの登録
St       = skapon.cns		;動作プログラムファイルの登録(最大10個くらい増やせます(St,St0,St1,St2......))
; ...

Turning it into this:

;-----必要なファイルの設定------------------------------------------

[Files]
movelist = movelist.dat
Cmd      = skapon.cmd		;入力コマンド定義ファイルの登録
Cns      = skapon.cns		;基本ステータス情報ファイルの登録
St       = skapon.cns		;動作プログラムファイルの登録(最大10個くらい増やせます(St,St0,St1,St2......))
; ...

The resulting program will, depending on the setting of IgnoreInlineComment, either add extra quotation marks to fields I'm not editing and thus corrupting the values, or force every single inline comment to be on a separate line when saving, neither of which is ideal.

; -----必要なファイルの設定------------------------------------------
[Files]
movelist = movelist.dat
Cmd      = """skapon.cmd		;入力コマンド定義ファイルの登録"""
Cns      = skapon.cns		;基本ステータス情報ファイルの登録
St       = skapon.cns		;動作プログラムファイルの登録(最大10個くらい増やせます(St,St0,St1,St2......))
;...
; -----必要なファイルの設定------------------------------------------
[Files]
movelist = movelist.dat
; 入力コマンド定義ファイルの登録
Cmd      = skapon.cmd
; 基本ステータス情報ファイルの登録
Cns      = skapon.cns
; 動作プログラムファイルの登録(最大10個くらい増やせます(St,St0,St1,St2......))
St       = skapon.cns
; ...

Additional context

The program this function comes from, Iguana, is intended to generate and patch characters for Ikemen GO, a free and open source fighting game engine. I mostly bring this up to clarify that the file format Iguana interfaces with, .def, uses INI syntax and should behave the same as any other INI file as far as this library is concerned.

I'm sure there's some easier way to do what I'm wanting to do here (adding a single line to a text file in a specific place), but it'd be nice to at least know if this is some weird edge case with this library or if I'm doing something wrong here.

I have an issue over on my project repo that documents this issue as well, if more context is necessary: SuperFromND/iguana#10

Code of Conduct

  • I agree to follow this project's Code of Conduct
@SuperFromND SuperFromND added the bug Something isn't working label Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant