gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.22k stars 7.55k forks source link

Replace to gopkg.in/yaml with github.com/goccy/go-yaml (slightly breaking change) #8822

Open bep opened 3 years ago

bep commented 3 years ago

Add this to have something to track this with.

The main blocker I see for this is that it's not possible to control location/timezone for dates without that information.

package main

import (
    "fmt"
    "log"

    v2 "gopkg.in/yaml.v2"
    v3 "gopkg.in/yaml.v3"
)

var data = `
d: 2021-07-15

`

func main() {
    mv2 := make(map[string]interface{})
    err := v2.Unmarshal([]byte(data), &mv2)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    fmt.Printf("--- mv2: %T %v \n", mv2["d"], mv2["d"])

    mv3 := make(map[string]interface{})
    err = v3.Unmarshal([]byte(data), &mv3)
    if err != nil {
        log.Fatalf("error: %v", err)
    }
    fmt.Printf("--- mv3: %T %v \n", mv3["d"], mv3["d"])
}

Prints:

--- mv2: string 2021-07-15 
--- mv3: time.Time 2021-07-15 00:00:00 +0000 UTC 

Note that v2 isn't perfect, either, but that at least allows us to handle known dates (e.g. the front matter dates).

bep commented 3 years ago

See https://github.com/go-yaml/yaml/issues/770

jmooring commented 9 months ago

Everyone once in a while a user gets burned by "on/off/yes/no" keys. This happened again yesterday. While I understand why this is blocked, I must say I have little sympathy for unqualified dates. If we could start over, or break some eggs, I'd place every unqualified date in Etc/UTC.

jmooring commented 3 weeks ago

Consider replacing github.com/go-yaml/yaml (last updated 2.5 years ago) with github.com/goccy/go-yaml which, at the moment, is actively maintained with 1.2k stars.

What we get:

bep commented 2 weeks ago

I must say I have little sympathy for unqualified dates.

Just to be clear, this is a very common "unqualified date" (for one, it's very easy to type, which I have sympathy for ...):

publishDate: 2021-07-15

Having the above mean UTC, would create very surprising beheaviour.