mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 13:40:38 +03:00
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
This commit is contained in:
parent
911bc60a7a
commit
912c6576bb
3 changed files with 36 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue