Skip to content

Commit

Permalink
Merge pull request #2 from MichaelMure/multiline
Browse files Browse the repository at this point in the history
add support for multi-line values with \
  • Loading branch information
pjbgf authored Mar 7, 2023
2 parents 6c58f93 + 80febc7 commit 3a3c614
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-git/gcfg/token"
)

var unescape = map[rune]rune{'\\': '\\', '"': '"', 'n': '\n', 't': '\t', 'b': '\b'}
var unescape = map[rune]rune{'\\': '\\', '"': '"', 'n': '\n', 't': '\t', 'b': '\b', '\n': '\n'}

// no error: invalid literals should be caught by scanner
func unquote(s string) string {
Expand Down
6 changes: 6 additions & 0 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ func TestReadWithCallback(t *testing.T) {
key5=
[sect1 "subsect2"]
[sect2]
[sect3]
foo = "!f(){ \
echo hello; \
};f"
`
expected := [][]string{
[]string{"sect1", "", "", "", "true"},
Expand All @@ -411,6 +415,8 @@ func TestReadWithCallback(t *testing.T) {
[]string{"sect1", "subsect1", "key5", "", "false"},
[]string{"sect1", "subsect2", "", "", "true"},
[]string{"sect2", "", "", "", "true"},
[]string{"sect3", "", "", "", "true"},
[]string{"sect3", "", "foo", "!f(){ \n\techo hello; \n\t};f", "false"},
}
err := ReadWithCallback(bytes.NewReader([]byte(text)), cb)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ func (s *Scanner) scanIdentifier() string {
return string(s.src[offs:s.offset])
}

// val indicate if we are scanning a value (vs a header)
func (s *Scanner) scanEscape(val bool) {
offs := s.offset
ch := s.ch
s.next() // always make progress
switch ch {
case '\\', '"':
case '\\', '"', '\n':
// ok
case 'n', 't', 'b':
if val {
Expand Down

0 comments on commit 3a3c614

Please sign in to comment.