aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser
diff options
context:
space:
mode:
authorJoe Mooring <[email protected]>2024-01-13 10:28:39 -0800
committerBjørn Erik Pedersen <[email protected]>2024-01-16 09:26:44 +0100
commit912c6576bb47535bb29819c9855da90580e11906 (patch)
tree3dc341ceafb1ed274bf6be4da63650febf4a0bbf /parser
parent911bc60a7ab739885908fdfe49d1578531940909 (diff)
downloadhugo-912c6576bb47535bb29819c9855da90580e11906.tar.gz
hugo-912c6576bb47535bb29819c9855da90580e11906.zip
parser/metadecoders: Add CSV lazyQuotes option to transform.Unmarshal
If true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field. It defaults to false. Closes #11884
Diffstat (limited to 'parser')
-rw-r--r--parser/metadecoders/decoder.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go
index 40b3a336c..35368e5a5 100644
--- a/parser/metadecoders/decoder.go
+++ b/parser/metadecoders/decoder.go
@@ -20,6 +20,7 @@ import (
"fmt"
"log"
"regexp"
+ "strconv"
"strings"
"github.com/gohugoio/hugo/common/herrors"
@@ -41,6 +42,10 @@ type Decoder struct {
// Comment, if not 0, is the comment character used in the CSV decoder. Lines beginning with the
// Comment character without preceding whitespace are ignored.
Comment rune
+
+ // If true, a quote may appear in an unquoted field and a non-doubled quote
+ // may appear in a quoted field. It defaults to false.
+ LazyQuotes bool
}
// OptionsKey is used in cache keys.
@@ -48,6 +53,7 @@ func (d Decoder) OptionsKey() string {
var sb strings.Builder
sb.WriteRune(d.Delimiter)
sb.WriteRune(d.Comment)
+ sb.WriteString(strconv.FormatBool(d.LazyQuotes))
return sb.String()
}
@@ -205,6 +211,7 @@ func (d Decoder) unmarshalCSV(data []byte, v any) error {
r := csv.NewReader(bytes.NewReader(data))
r.Comma = d.Delimiter
r.Comment = d.Comment
+ r.LazyQuotes = d.LazyQuotes
records, err := r.ReadAll()
if err != nil {