From 81eb6bfe6fdbb1880ed96867a874c4c8640a5cab Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Wed, 1 Nov 2023 12:10:03 -0700 Subject: [PATCH] fix: Support comments inside devcontainer-feature.json (#62) --- devcontainer/features/features.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/devcontainer/features/features.go b/devcontainer/features/features.go index e1afc2c..eb7f1e5 100644 --- a/devcontainer/features/features.go +++ b/devcontainer/features/features.go @@ -15,6 +15,7 @@ import ( "github.com/go-git/go-billy/v5" "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/tailscale/hujson" ) // Extract unpacks the feature from the image and returns the @@ -113,9 +114,16 @@ func Extract(fs billy.Filesystem, directory, reference string) (*Spec, error) { return nil, fmt.Errorf("open devcontainer-feature.json: %w", err) } defer featureFile.Close() - var spec *Spec - err = json.NewDecoder(featureFile).Decode(&spec) + featureFileBytes, err := io.ReadAll(featureFile) + if err != nil { + return nil, fmt.Errorf("read devcontainer-feature.json: %w", err) + } + standardizedFeatureFileBytes, err := hujson.Standardize(featureFileBytes) if err != nil { + return nil, fmt.Errorf("standardize devcontainer-feature.json: %w", err) + } + var spec *Spec + if err := json.Unmarshal(standardizedFeatureFileBytes, &spec); err != nil { return nil, fmt.Errorf("decode devcontainer-feature.json: %w", err) } // See https://containers.dev/implementors/features/#devcontainer-feature-json-properties