If the configuration item of my ini configuration file contains #, it will cause an error in reading the configuration.
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
- [X] I agree to follow this project's Code of Conduct
I second that. This should really be addressed.
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
}
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`
You can also use triple quotes:
key = """some#thing"""