Skip to content

Commit

Permalink
Prevent panic when 'options' value is nil (#3947)
Browse files Browse the repository at this point in the history
* Prevent panic when 'options' value is nil

* Add test case
  • Loading branch information
joanlopez authored Sep 12, 2024
1 parent 547fc08 commit 535a5bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 535a5bb

Please sign in to comment.