summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-ini/ini/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-ini/ini/parser.go')
-rw-r--r--vendor/github.com/go-ini/ini/parser.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/vendor/github.com/go-ini/ini/parser.go b/vendor/github.com/go-ini/ini/parser.go
index f8ac8026a..db3af8f00 100644
--- a/vendor/github.com/go-ini/ini/parser.go
+++ b/vendor/github.com/go-ini/ini/parser.go
@@ -193,7 +193,9 @@ func hasSurroundedQuote(in string, quote byte) bool {
strings.IndexByte(in[1:], quote) == len(in)-2
}
-func (p *parser) readValue(in []byte, ignoreContinuation, ignoreInlineComment, unescapeValueDoubleQuotes bool) (string, error) {
+func (p *parser) readValue(in []byte,
+ ignoreContinuation, ignoreInlineComment, unescapeValueDoubleQuotes, unescapeValueCommentSymbols bool) (string, error) {
+
line := strings.TrimLeftFunc(string(in), unicode.IsSpace)
if len(line) == 0 {
return "", nil
@@ -243,6 +245,13 @@ func (p *parser) readValue(in []byte, ignoreContinuation, ignoreInlineComment, u
if hasSurroundedQuote(line, '\'') ||
hasSurroundedQuote(line, '"') {
line = line[1 : len(line)-1]
+ } else if len(valQuote) == 0 && unescapeValueCommentSymbols {
+ if strings.Contains(line, `\;`) {
+ line = strings.Replace(line, `\;`, ";", -1)
+ }
+ if strings.Contains(line, `\#`) {
+ line = strings.Replace(line, `\#`, "#", -1)
+ }
}
return line, nil
}
@@ -261,6 +270,10 @@ func (f *File) parse(reader io.Reader) (err error) {
}
section, _ := f.NewSection(name)
+ // This "last" is not strictly equivalent to "previous one" if current key is not the first nested key
+ var isLastValueEmpty bool
+ var lastRegularKey *Key
+
var line []byte
var inUnparseableSection bool
for !p.isEOF {
@@ -269,6 +282,14 @@ func (f *File) parse(reader io.Reader) (err error) {
return err
}
+ if f.options.AllowNestedValues &&
+ isLastValueEmpty && len(line) > 0 {
+ if line[0] == ' ' || line[0] == '\t' {
+ lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
+ continue
+ }
+ }
+
line = bytes.TrimLeftFunc(line, unicode.IsSpace)
if len(line) == 0 {
continue
@@ -333,7 +354,8 @@ func (f *File) parse(reader io.Reader) (err error) {
kname, err := p.readValue(line,
f.options.IgnoreContinuation,
f.options.IgnoreInlineComment,
- f.options.UnescapeValueDoubleQuotes)
+ f.options.UnescapeValueDoubleQuotes,
+ f.options.UnescapeValueCommentSymbols)
if err != nil {
return err
}
@@ -359,10 +381,12 @@ func (f *File) parse(reader io.Reader) (err error) {
value, err := p.readValue(line[offset:],
f.options.IgnoreContinuation,
f.options.IgnoreInlineComment,
- f.options.UnescapeValueDoubleQuotes)
+ f.options.UnescapeValueDoubleQuotes,
+ f.options.UnescapeValueCommentSymbols)
if err != nil {
return err
}
+ isLastValueEmpty = len(value) == 0
key, err := section.NewKey(kname, value)
if err != nil {
@@ -371,6 +395,7 @@ func (f *File) parse(reader io.Reader) (err error) {
key.isAutoIncrement = isAutoIncr
key.Comment = strings.TrimSpace(p.comment.String())
p.comment.Reset()
+ lastRegularKey = key
}
return nil
}