mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02: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:
committed by
Bjørn Erik Pedersen
parent
911bc60a7a
commit
912c6576bb
@@ -107,3 +107,29 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
_, err := b.BuildE()
|
||||
b.Assert(err.Error(), qt.Contains, "error calling highlight: invalid Highlight option: 0")
|
||||
}
|
||||
|
||||
// Issue #11884
|
||||
func TestUnmarshalCSVLazyDecoding(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- assets/pets.csv --
|
||||
name,description,age
|
||||
Spot,a nice dog,3
|
||||
Rover,"a big dog",5
|
||||
Felix,a "malicious" cat,7
|
||||
Bella,"an "evil" cat",9
|
||||
Scar,"a "dead cat",11
|
||||
-- layouts/index.html --
|
||||
{{ $opts := dict "lazyQuotes" true }}
|
||||
{{ $data := resources.Get "pets.csv" | transform.Unmarshal $opts }}
|
||||
{{ printf "%v" $data | safeHTML }}
|
||||
`
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
[[name description age] [Spot a nice dog 3] [Rover a big dog 5] [Felix a "malicious" cat 7] [Bella an "evil" cat 9] [Scar a "dead cat 11]]
|
||||
`)
|
||||
}
|
||||
|
Reference in New Issue
Block a user