ini icon indicating copy to clipboard operation
ini copied to clipboard

"=" character not escaped properly

Open Tim-Blyth-SiteHost opened this issue 3 years ago • 1 comments

Version

go1.19.3 linux/amd64

Describe the bug

If a value contains the "=" character, the library will write it to the output file without escaping it. This causes PHP to fail when attempting to load the .ini file with the error PHP Warning: syntax error, unexpected '=' in test.ini on line 27

To reproduce

writeini.go:

package main

import (
	"github.com/go-ini/ini"
)

func main() {
	f := ini.Empty()

	test, _ := f.NewSection("test")
	_, _ = test.NewKey("test", "=")

	_ = f.SaveTo("./test.ini")
}

testini.php:

<?php
$ini_array = parse_ini_file("test.ini", true);
print_r($ini_array);
$ go run writeini.go
$ php testini.php   
PHP Warning:  syntax error, unexpected '=' in test.ini on line 2
 in ~/testini.php on line 2

Expected behavior

The library should wrap values with = characters in quotes, like it does for other characters

Additional context

No response

Code of Conduct

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

Tim-Blyth-SiteHost avatar Nov 30 '22 04:11 Tim-Blyth-SiteHost

You could try wrapping the variable with backticks

example: [test] test=#=/

awanganddong avatar Dec 10 '22 09:12 awanganddong