Skip to content

Commit aa60563

Browse files
[6.x] Fix save crash after deleting a Bard set containing a hidden field (#15008)
1 parent 49a3630 commit aa60563

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

resources/js/components/publish/Values.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ function data_delete(obj, path) {
66
var parts = path.split('.');
77
while (parts.length - 1) {
88
var key = parts.shift();
9+
if (obj === null || typeof obj !== 'object') return;
910
var shouldBeArray = parts.length ? new RegExp('^[0-9]+$').test(parts[0]) : false;
1011
if (!(key in obj)) obj[key] = shouldBeArray ? [] : {};
1112
obj = obj[key];
1213
}
13-
delete obj[parts[0]];
14+
if (obj !== null && typeof obj === 'object') delete obj[parts[0]];
1415
}
1516

1617
export default class Values {
@@ -82,7 +83,7 @@ export default class Values {
8283

8384
missingValue(dottedKey) {
8485
var properties = Array.isArray(dottedKey) ? dottedKey : dottedKey.split('.');
85-
var value = properties.reduce((prev, curr) => prev && prev[curr], clone(this.values));
86+
var value = properties.reduce((prev, curr) => (prev == null ? undefined : prev[curr]), clone(this.values));
8687

8788
return value === undefined;
8889
}

resources/js/tests/PublishValues.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,21 @@ test('it properly sets keys that javascript considers having numeric separators'
562562

563563
expect(newValues).toEqual(expected);
564564
});
565+
566+
test('it does not throw when rejecting a value nested under a null node', () => {
567+
let values = {
568+
first_name: 'Han',
569+
ship: {
570+
crew: null,
571+
},
572+
};
573+
574+
let rejected = new Values(values).except(['ship.crew.0.name']);
575+
576+
expect(rejected).toEqual({
577+
first_name: 'Han',
578+
ship: {
579+
crew: null,
580+
},
581+
});
582+
});

0 commit comments

Comments
 (0)