Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
29 lines
1.0 KiB
Plaintext
29 lines
1.0 KiB
Plaintext
import { isSafeFromPollution } from './utilities.js';
|
|
export const processNested = function(data) {
|
|
if (!data || data.length < 1) {
|
|
return Object.create(null);
|
|
}
|
|
const d = Object.create(null), keys = Object.keys(data);
|
|
for(let i = 0; i < keys.length; i++){
|
|
const key = keys[i], keyParts = key?.replace(new RegExp(/\[/g), '.').replace(new RegExp(/\]/g), '').split('.'), value = data[key];
|
|
let current = d;
|
|
for(let index = 0; index < keyParts.length; index++){
|
|
const k = keyParts[index];
|
|
// Ensure we don't allow prototype pollution
|
|
if (!isSafeFromPollution(current, k)) {
|
|
continue;
|
|
}
|
|
if (index >= keyParts.length - 1) {
|
|
current[k] = value;
|
|
} else {
|
|
if (!current[k]) {
|
|
current[k] = !keyParts[index + 1] ? [] : Object.create(null);
|
|
}
|
|
current = current[k];
|
|
}
|
|
}
|
|
}
|
|
return d;
|
|
};
|
|
|
|
//# sourceMappingURL=processNested.js.map |