Skip to content

Commit b75392a

Browse files
committed
fix(router): harden routes graph children parsing
closes #539
1 parent e73a86c commit b75392a

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

‎src/resources/js/routes.js‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,32 @@ document.addEventListener('DOMContentLoaded', function () {
2626
var tree = ROUTES_INDEX;
2727

2828
function cleanStringChildren(obj) {
29+
if (!obj || typeof obj !== 'object') {
30+
return;
31+
}
2932
for (var property in obj) {
30-
if (obj.hasOwnProperty(property)) {
31-
if (property === 'children' && typeof obj[property] === 'object') {
32-
for (var i = obj[property].length - 1; i >= 0; i--) {
33-
if (typeof obj[property][i] === 'string') {
34-
obj[property].splice(i, 1);
33+
if (Object.prototype.hasOwnProperty.call(obj, property)) {
34+
if (property === 'children') {
35+
if (typeof obj[property] === 'string') {
36+
obj[property] = [];
37+
continue;
38+
}
39+
40+
if (Array.isArray(obj[property])) {
41+
for (var i = obj[property].length - 1; i >= 0; i--) {
42+
if (
43+
typeof obj[property][i] !== 'object' ||
44+
obj[property][i] === null
45+
) {
46+
obj[property].splice(i, 1);
47+
}
3548
}
49+
} else if (obj[property] && typeof obj[property] === 'object') {
50+
obj[property] = [];
3651
}
3752
}
38-
if (typeof obj[property] === 'object') {
53+
54+
if (obj[property] && typeof obj[property] === 'object') {
3955
cleanStringChildren(obj[property]);
4056
}
4157
}

0 commit comments

Comments
 (0)