forked from GitHub/virtualtabletop
enforce id
to be a string (#2313)
This commit is contained in:
parent
1d57f387dd
commit
9e30ec63f6
@ -2080,6 +2080,8 @@ function jeGetContext() {
|
||||
|
||||
if(!jeStateNow.id)
|
||||
jeJSONerror = 'No ID given.';
|
||||
else if(typeof jeStateNow.id != 'string')
|
||||
jeJSONerror = 'ID has to be a string.';
|
||||
else if(JSON.parse(jeStateBefore).id != jeStateNow.id && widgets.has(jeStateNow.id))
|
||||
jeJSONerror = `ID ${jeStateNow.id} is already in use.`;
|
||||
else if(jeStateNow.parent !== undefined && jeStateNow.parent !== null && !widgets.has(jeStateNow.parent))
|
||||
|
@ -108,6 +108,8 @@ export function addWidget(widget, instance) {
|
||||
async function addWidgetLocal(widget) {
|
||||
if (!widget.id)
|
||||
widget.id = generateUniqueWidgetID();
|
||||
else
|
||||
widget.id = String(widget.id);
|
||||
|
||||
if(widget.parent && !widgets.has(widget.parent)) {
|
||||
console.error(`Refusing to add widget ${widget.id} with invalid parent ${widget.parent}.`);
|
||||
|
@ -1738,12 +1738,14 @@ export class Widget extends StateManaged {
|
||||
let newState = JSON.parse(JSON.stringify(oldWidget.state));
|
||||
newState.id = await compute(a.relation, null, oldWidget.get(a.property), a.value);
|
||||
|
||||
if(!widgets.has(newState.id)) {
|
||||
if(widgets.has(newState.id)) {
|
||||
problems.push(`id ${newState.id} already in use, ignored.`);
|
||||
} else if(typeof newState.id != 'string' || newState.id.length == 0) {
|
||||
problems.push(`id ${newState.id} is not a string or empty, ignored.`);
|
||||
} else {
|
||||
await updateWidgetId(newState, oldID);
|
||||
for(const c in collections)
|
||||
collections[c] = collections[c].map(w=>w.id==oldID ? widgets.get(newState.id) : w);
|
||||
} else {
|
||||
problems.push(`id ${newState.id} already in use, ignored.`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user