Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDAAP-49] fix(events) Exception being thrown on post to the events e… #1742

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

marwoodandrew
Copy link
Contributor

…ndpoint

@MarkLark86
Copy link
Collaborator

I think this would be more of a client error rather than an API error, so we should probably stop the client sending this data rather than supporting the client to send invalid data.

We already have code similar to this for both Events & Planning, to sanitise the request data. Might be good to extend this functionality for both on the client.

And probably make it more generic, and work directly with any field that starts with a specific set of characters. i.e.

function removeFieldsStartingWith(updates: {[key: string]: Array<any> | any}, prefix: string) {
    Object.keys(updates).forEach((field) => {
        if (!Array.isArray(updates[field])) {
            if (field.startsWith(prefix)) {
                delete updates[field];
            }
        } else {
            updates[field].forEach((arrayEntry) => {
                Object.keys(arrayEntry).forEach((arrayEntryField) => {
                    if (arrayEntryField.startsWith(prefix)) {
                        delete arrayEntry[arrayEntryField];
                    }
                });
            });
        }
    });
}

Then calling it like this:

removeFieldsStartingWith(updates, '$$');

Would remove any values starting with $$ from the top level field as well as any field inside an array of values

@MarkLark86 MarkLark86 merged commit 19bccaa into superdesk:develop Dec 7, 2022
MarkLark86 pushed a commit to MarkLark86/superdesk-planning that referenced this pull request Dec 7, 2022
@MarkLark86 MarkLark86 added the merged Merged into release branch label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged Merged into release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants