-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fix(Polyline): safeguard points arg from options #9855
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
Build Stats
|
Isn't 'fromObject' already doing it safely? how do you get to the bug? |
this is fun:
vs
|
I would think this was safeguarding us for all classes /**
*
* @param {Function} klass
* @param {object} object
* @param {object} [options]
* @param {string} [options.extraParam] property to pass as first argument to the constructor
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
* @returns {Promise<FabricObject>}
*/
static _fromObject<S extends FabricObject>(
{ type, ...object }: Record<string, unknown>,
{ extraParam, ...options }: Abortable & { extraParam?: string } = {}
): Promise<S> {
return enlivenObjectEnlivables<any>(cloneDeep(object), options).then(
(enlivedMap) => {
const allOptions = { ...options, ...enlivedMap };
// from the resulting enlived options, extract options.extraParam to arg0
// to avoid accidental overrides later
if (extraParam) {
const { [extraParam]: arg0, ...rest } = allOptions;
// @ts-expect-error different signature
return new this(arg0, rest);
} else {
return new this(allOptions);
}
}
) as Promise<S>;
} Of course i don't care to safeguard it twice. This could also be safeguarded with typings, saying that the props have never 'points' and should be done also for the other classes probably like text, path and so on |
It is safeguard by fromObject which was the cause of the original issue we want to resolve. But still if the dev calls If you want to avoid object spreads from now on just say so and I will try to avoid |
No i don't want to avoid spreads in general. |
Description
Passing the following will result in points2 being set as the polyline points
This PR fixes that and adds a test for it
closes #8296
In Action