diff --git a/internal/config/plugin_manager.go b/internal/config/plugin_manager.go index d64aab11de..1c5bfd8bd2 100644 --- a/internal/config/plugin_manager.go +++ b/internal/config/plugin_manager.go @@ -1,9 +1,9 @@ package config import ( - "bytes" - "encoding/json" "errors" + + "github.com/micro-editor/json5" ) var ( @@ -35,10 +35,7 @@ type PluginInfo struct { func NewPluginInfo(data []byte) (*PluginInfo, error) { var info []PluginInfo - dec := json.NewDecoder(bytes.NewReader(data)) - // dec.DisallowUnknownFields() // Force errors - - if err := dec.Decode(&info); err != nil { + if err := json5.Unmarshal(data, &info); err != nil { return nil, err } diff --git a/internal/config/plugin_manager_test.go b/internal/config/plugin_manager_test.go new file mode 100644 index 0000000000..f360469a04 --- /dev/null +++ b/internal/config/plugin_manager_test.go @@ -0,0 +1,23 @@ +package config + +import "testing" + +func TestNewPluginInfoAllowsJSON5Comments(t *testing.T) { + data := []byte(`[ + // repo.json files are decoded as JSON5 by the plugin installer. + { + "Name": "example", + "Description": "Example plugin", + "Website": "https://example.com" + } +]`) + + info, err := NewPluginInfo(data) + if err != nil { + t.Fatal(err) + } + + if info.Name != "example" { + t.Fatalf("expected plugin name %q, got %q", "example", info.Name) + } +}