Skip to content

Commit 3a3c614

Browse files
authored
Merge pull request #2 from MichaelMure/multiline
add support for multi-line values with \
2 parents 6c58f93 + 80febc7 commit 3a3c614

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/go-git/gcfg/token"
1313
)
1414

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

1717
// no error: invalid literals should be caught by scanner
1818
func unquote(s string) string {

read_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ func TestReadWithCallback(t *testing.T) {
400400
key5=
401401
[sect1 "subsect2"]
402402
[sect2]
403+
[sect3]
404+
foo = "!f(){ \
405+
echo hello; \
406+
};f"
403407
`
404408
expected := [][]string{
405409
[]string{"sect1", "", "", "", "true"},
@@ -411,6 +415,8 @@ func TestReadWithCallback(t *testing.T) {
411415
[]string{"sect1", "subsect1", "key5", "", "false"},
412416
[]string{"sect1", "subsect2", "", "", "true"},
413417
[]string{"sect2", "", "", "", "true"},
418+
[]string{"sect3", "", "", "", "true"},
419+
[]string{"sect3", "", "foo", "!f(){ \n\techo hello; \n\t};f", "false"},
414420
}
415421
err := ReadWithCallback(bytes.NewReader([]byte(text)), cb)
416422
if err != nil {

scanner/scanner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ func (s *Scanner) scanIdentifier() string {
155155
return string(s.src[offs:s.offset])
156156
}
157157

158+
// val indicate if we are scanning a value (vs a header)
158159
func (s *Scanner) scanEscape(val bool) {
159160
offs := s.offset
160161
ch := s.ch
161162
s.next() // always make progress
162163
switch ch {
163-
case '\\', '"':
164+
case '\\', '"', '\n':
164165
// ok
165166
case 'n', 't', 'b':
166167
if val {

0 commit comments

Comments
 (0)