Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/config/plugin_manager.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package config

import (
"bytes"
"encoding/json"
"errors"

"github.com/micro-editor/json5"
)

var (
Expand Down Expand Up @@ -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
}

Expand Down
23 changes: 23 additions & 0 deletions internal/config/plugin_manager_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading