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 [];
|
||||||
}
|
}
|
||||||
return flattenObjectEntries(
|
return flattenObjectEntries(
|
||||||
Object.entries(parseCookie(this.getCookie()))
|
Object.entries(parseCookie(this.getCookie())).map(([key, value]) => [
|
||||||
.map(([key, value]) => [key, value || ""])
|
key,
|
||||||
.map(([key, value]) => {
|
value || "",
|
||||||
return [key, StolenDataEntry.parseValue(value)];
|
]),
|
||||||
})
|
StolenDataEntry.parseValue
|
||||||
).map(([key, value]) => new StolenDataEntry(this, "cookie", key, value));
|
).map(([key, value]) => new StolenDataEntry(this, "cookie", key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ export default class ExtendedRequest {
|
||||||
.map((header) => {
|
.map((header) => {
|
||||||
return [
|
return [
|
||||||
header.name,
|
header.name,
|
||||||
StolenDataEntry.parseValue(decodeURIComponent(header.value)),
|
StolenDataEntry.parseValue(safeDecodeURIComponent(header.value)),
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
).map(([key, value]) => new StolenDataEntry(this, "header", key, value));
|
).map(([key, value]) => new StolenDataEntry(this, "header", key, value));
|
||||||
|
|
14
util.ts
14
util.ts
|
@ -204,22 +204,24 @@ export function flattenObject(
|
||||||
ret = [],
|
ret = [],
|
||||||
parsed = false
|
parsed = false
|
||||||
): [string, string][] {
|
): [string, string][] {
|
||||||
|
const prefix = key === "" ? "" : `${key}.`;
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
for (let i in obj) {
|
if (obj.length == 1) {
|
||||||
flattenObject(obj[i], parser, key + "." + i, ret);
|
flattenObject(obj[0], parser, key, ret);
|
||||||
|
} else {
|
||||||
|
for (let i in obj) {
|
||||||
|
flattenObject(obj[i], parser, prefix + i, ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (typeof obj === "object") {
|
} else if (typeof obj === "object") {
|
||||||
for (const [subkey, value] of Object.entries(obj)) {
|
for (const [subkey, value] of Object.entries(obj)) {
|
||||||
flattenObject(value, parser, key + "." + subkey, ret);
|
flattenObject(value, parser, prefix + subkey, ret);
|
||||||
}
|
}
|
||||||
} else if (!parsed) {
|
} else if (!parsed) {
|
||||||
flattenObject(parser(obj), parser, key, ret, true);
|
flattenObject(parser(obj), parser, key, ret, true);
|
||||||
} else {
|
} else {
|
||||||
ret.push([key, obj]);
|
ret.push([key, obj]);
|
||||||
}
|
}
|
||||||
if (key == "") {
|
|
||||||
console.log("FLATTENING!", obj, ret);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user