mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-24 09:49:24 +02:00
Remove dependency express-fileupload
This commit is contained in:
parent
1dbfb5637a
commit
7aa7e662b2
20 changed files with 2782 additions and 23 deletions
35
server/libs/expressFileupload/processNested.js
Normal file
35
server/libs/expressFileupload/processNested.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const { isSafeFromPollution } = require("./utilities");
|
||||
|
||||
module.exports = function(data){
|
||||
if (!data || data.length < 1) return Object.create(null);
|
||||
|
||||
let d = Object.create(null),
|
||||
keys = Object.keys(data);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i],
|
||||
value = data[key],
|
||||
current = d,
|
||||
keyParts = key
|
||||
.replace(new RegExp(/\[/g), '.')
|
||||
.replace(new RegExp(/\]/g), '')
|
||||
.split('.');
|
||||
|
||||
for (let index = 0; index < keyParts.length; index++){
|
||||
let 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] = !isNaN(keyParts[index + 1]) ? [] : Object.create(null);
|
||||
current = current[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
return d;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue