8000 If the configuration item of my ini configuration file contains #, it will cause an error in reading the configuration. · Issue #328 · go-ini/ini · GitHub
[go: up one dir, main page]

Skip to content

If the configuration item of my ini configuration file contains #, it will cause an error in reading the configuration. #328

Closed

Description

@chingzio

Version

1.67.0

Describe the bug

If the configuration item of my ini configuration file contains #, it will cause the configuration to be read incorrectly. For example, my MySQL password is "xxx#123", and the obtained parameter is "xxx".

To reproduce

ini file

[database]
DbPassWord = "XXX#123"

config.go

file, err := ini.Load("config/app.ini")
DbPassWord = file.Section("database").Key("DbPassWord").MustString("")
fmt.Println("passwd:"DbPassWord)

This outputs passwd: "XXX

Expected behavior

Configuration items containing # can be read correctly.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. Tensai75 commented on Jan 30, 2023

    @Tensai75

    I second that. This should really be addressed.

  2. egorlepa commented on Mar 1, 2023

    @egorlepa

    same problem, can't have values with #
    workaround:

    func extractValue(key *ini.Key) string {
    	value := key.Value()
    	comment := key.Comment
    	if len(comment) == 0 {
    		return value
    	}
    	if idx := strings.LastIndex(comment, "\n"); idx != -1 {
    		comment = comment[idx+1:]
    	}
    	if len(comment) > 0 && comment[0] == '#' {
    		value += comment
    	}
    	return value
    }
  3. chingzio commented on Mar 1, 2023

    @chingzio
    Author

    I found a solution, you can use ` instead of " in the ini file, and you can read the configuration correctly.
    for example:

    [database]
    DbPassWord = `XXX#123`

  4. CodeMonkey80s commented on Jan 12, 2024

    @CodeMonkey80s

    You can also use triple quotes:

    key = """some#thing"""
    
  5. unknwon commented on Nov 11, 2026

    @unknwon
    Member

    Fixed in v2 by #435, and will be in the next v2 pre-release after v2.0.0-beta.2. v2 is imported as unknwon.dev/ini/v2; see the migration guide for upgrading from v1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0