Use the new flattening across other sources of data. Remove leading "." for entries one level deep
This commit is contained in:
parent
d33615987b
commit
97dc99dba9
@ -188,11 +188,11 @@ export default class ExtendedRequest {
|
||||
return [];
|
||||
}
|
||||
return flattenObjectEntries(
|
||||
Object.entries(parseCookie(this.getCookie()))
|
||||
.map(([key, value]) => [key, value || ""])
|
||||
.map(([key, value]) => {
|
||||
return [key, StolenDataEntry.parseValue(value)];
|
||||
})
|
||||
Object.entries(parseCookie(this.getCookie())).map(([key, value]) => [
|
||||
key,
|
||||
value || "",
|
||||
]),
|
||||
StolenDataEntry.parseValue
|
||||
).map(([key, value]) => new StolenDataEntry(this, "cookie", key, value));
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ export default class ExtendedRequest {
|
||||
.map((header) => {
|
||||
return [
|
||||
header.name,
|
||||
StolenDataEntry.parseValue(decodeURIComponent(header.value)),
|
||||
StolenDataEntry.parseValue(safeDecodeURIComponent(header.value)),
|
||||
];
|
||||
})
|
||||
).map(([key, value]) => new StolenDataEntry(this, "header", key, value));
|
||||
|
14
util.ts
14
util.ts
@ -204,22 +204,24 @@ export function flattenObject(
|
||||
ret = [],
|
||||
parsed = false
|
||||
): [string, string][] {
|
||||
const prefix = key === "" ? "" : `${key}.`;
|
||||
if (Array.isArray(obj)) {
|
||||
for (let i in obj) {
|
||||
flattenObject(obj[i], parser, key + "." + i, ret);
|
||||
if (obj.length == 1) {
|
||||
flattenObject(obj[0], parser, key, ret);
|
||||
} else {
|
||||
for (let i in obj) {
|
||||
flattenObject(obj[i], parser, prefix + i, ret);
|
||||
}
|
||||
}
|
||||
} else if (typeof obj === "object") {
|
||||
for (const [subkey, value] of Object.entries(obj)) {
|
||||
flattenObject(value, parser, key + "." + subkey, ret);
|
||||
flattenObject(value, parser, prefix + subkey, ret);
|
||||
}
|
||||
} else if (!parsed) {
|
||||
flattenObject(parser(obj), parser, key, ret, true);
|
||||
} else {
|
||||
ret.push([key, obj]);
|
||||
}
|
||||
if (key == "") {
|
||||
console.log("FLATTENING!", obj, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user