From 66e46d0ce437c7080b79753ef545cd0e15f39dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Thu, 12 Sep 2024 11:07:07 +0200 Subject: [PATCH 1/2] Prevent panic when 'options' value is nil --- js/bundle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bundle.go b/js/bundle.go index 39368aa40b3..a6c28290b70 100644 --- a/js/bundle.go +++ b/js/bundle.go @@ -197,7 +197,7 @@ func (b *Bundle) populateExports(updateOptions bool, bi *BundleInstance) error { } switch k { case consts.Options: - if !updateOptions { + if !updateOptions || v == nil { continue } var data []byte From 2d8777a10d14037d800489798e3600d48cae79a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20L=C3=B3pez=20de=20la=20Franca=20Beltran?= Date: Thu, 12 Sep 2024 11:45:20 +0200 Subject: [PATCH 2/2] Add test case --- js/bundle_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/bundle_test.go b/js/bundle_test.go index ee7853a1f5d..a0f48a8af7a 100644 --- a/js/bundle_test.go +++ b/js/bundle_test.go @@ -214,6 +214,16 @@ func TestNewBundle(t *testing.T) { `) require.NoError(t, err) }) + t.Run("Null", func(t *testing.T) { + t.Parallel() + fs := fsext.NewMemMapFs() + require.NoError(t, fsext.WriteFile(fs, "/options.js", []byte("module.exports={}"), 0o644)) + _, err := getSimpleBundle(t, "/script.js", ` + export {options} from "./options.js"; + export default function() {}; + `, fs) + require.NoError(t, err) + }) t.Run("Invalid", func(t *testing.T) { t.Parallel() invalidOptions := map[string]struct {