From ddbaf6a4bb4081251aa660d1983f25bf83c5e95f Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Fri, 23 May 2025 21:44:23 +0300 Subject: [PATCH] refactor(tracker): use UnmarshalStrict when decoding embedded yamls Since we have 100% control over what data gets embedded, there is no reason to embed anything that doesn't pass the strict yaml parsing and it's better we throw a panic right away so it's easy to catch this during development. --- tracker/gioui/keyevent.go | 2 +- tracker/gioui/preferences.go | 2 +- tracker/presets.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tracker/gioui/keyevent.go b/tracker/gioui/keyevent.go index f7a9547..e4eddac 100644 --- a/tracker/gioui/keyevent.go +++ b/tracker/gioui/keyevent.go @@ -41,7 +41,7 @@ var defaultKeyBindingsYaml []byte func loadDefaultKeyBindings() []KeyBinding { var keyBindings []KeyBinding - err := yaml.Unmarshal(defaultKeyBindingsYaml, &keyBindings) + err := yaml.UnmarshalStrict(defaultKeyBindingsYaml, &keyBindings) if err != nil { panic(fmt.Errorf("failed to unmarshal keybindings: %w", err)) } diff --git a/tracker/gioui/preferences.go b/tracker/gioui/preferences.go index fbd2d55..2a04384 100644 --- a/tracker/gioui/preferences.go +++ b/tracker/gioui/preferences.go @@ -29,7 +29,7 @@ var defaultPreferencesYaml []byte func loadDefaultPreferences() Preferences { var preferences Preferences - err := yaml.Unmarshal(defaultPreferencesYaml, &preferences) + err := yaml.UnmarshalStrict(defaultPreferencesYaml, &preferences) if err != nil { panic(fmt.Errorf("failed to unmarshal preferences: %w", err)) } diff --git a/tracker/presets.go b/tracker/presets.go index eabf4ba..25c2e67 100644 --- a/tracker/presets.go +++ b/tracker/presets.go @@ -11,7 +11,7 @@ import ( "github.com/vsariola/sointu" "github.com/vsariola/sointu/vm" - "gopkg.in/yaml.v3" + "gopkg.in/yaml.v2" ) //go:generate go run generate/main.go @@ -180,7 +180,7 @@ func init() { return nil } var instr sointu.Instrument - if yaml.Unmarshal(data, &instr) == nil { + if yaml.UnmarshalStrict(data, &instr) == nil { noExt := path[:len(path)-len(filepath.Ext(path))] splitted := splitPath(noExt) splitted = splitted[1:] // remove "presets" from the path