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

fix(): Avoid errors on restoring custom properties that pass the lazy detection of shadow,gradient,pattern and clipPath #10017

Merged
merged 11 commits into from
Aug 4, 2024

Conversation

zhe-he
Copy link
Contributor

@zhe-he zhe-he commented Jul 22, 2024

When importing, each property of the object will be iterated over. If a property has type and source, additional logic will be executed. If the user has custom-exported additional properties, and the property is an object with type or source keywords, the user needs to output it as is.

Copy link

codesandbox bot commented Jul 22, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@asturur
Copy link
Member

asturur commented Jul 25, 2024

Ok i see your point, but we can't return value on a catch, it will make unparsed pattern returned as is with errors later.
We need make stronger the check. i ll try to make some examples

@asturur
Copy link
Member

asturur commented Jul 25, 2024

Maybe we can change:

const promises = Object.values(serializedObject).map((value: any) => {

to

const promises = Object.entries(serializedObject).map(([key, value]: any[]) => {

and then we can use if ['gradient', 'shadow', 'clipPath'].includes(key) && value.type

that will make custom properties safe.

And you can do the same for patterns?

@zhe-he
Copy link
Contributor Author

zhe-he commented Jul 26, 2024

done.

@asturur asturur changed the title fix: custom-attr-type fix(): Avoid errors on restoring custom properties that pass the lazy detection of shadow,gradient,pattern and clipPath Jul 30, 2024
@asturur
Copy link
Member

asturur commented Aug 4, 2024

Adding a test and merging

'stroke',
'path',
'backgroundImage',
'overlayImage',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we forgot 3 cases.

@asturur
Copy link
Member

asturur commented Aug 4, 2024

I m having a second thought we did it the wrong fix here.

@asturur
Copy link
Member

asturur commented Aug 4, 2024

@zhe-he look at how i changed it, and let me know.

@asturur asturur merged commit edec141 into fabricjs:master Aug 4, 2024
18 of 20 checks passed
@zhe-he
Copy link
Contributor Author

zhe-he commented Aug 5, 2024

@asturur
The previous commit modifications are clear to me. I noticed that the last commit marked as 'ok' was reverted, and I don't understand whether it was due to our changes causing other bugs or if it was due to errors from a merge conflict.

@asturur
Copy link
Member

asturur commented Aug 5, 2024

The fix we made with the properties was making impossible extend a class with a restorable property. because if you added a custom property like 'mask' with a restorable object, then the allow list we built would have blocked you

@zhe-he
Copy link
Contributor Author

zhe-he commented Aug 6, 2024

Using hasClass is not very reliable either. I might have a custom attribute whose type value happens to exist in Fabric's types, such as Rect, Textbox, Path, etc. Can we first check if the key is a Fabric property, and then check if the value exists in the classRegistry?

@asturur
Copy link
Member

asturur commented Aug 6, 2024

That would be bad design on implementer side.
In fabric an object with type: rect is a rect. period.
We can't block everyone from adding rects to custom properties because someone could use objects with 'type: rect' that are not rects.

Why shoud you block someone from adding a custom property that is correctly enlivable?

@zhe-he
Copy link
Contributor Author

zhe-he commented Aug 6, 2024

Okay, if this is reasonable, then it is indeed unnecessary to over-design. I agree with you that allowing users to customize properties of built-in objects is a good idea.

@zhe-he zhe-he deleted the fix-custom-attr-type branch August 6, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants