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(SVGParser) ignore missing xlink target issue on svg parsing #9427

Merged

Conversation

gloriousjob
Copy link
Contributor

Motivation

@closes #9109

Description

Sometimes an svg has use tags with an xlink with no target, which most parsers ignore. We should ignore these use tags as well.

Changes

Adds a null check and returns early, preventing an NPE.
Also removed elementById since it was needed for IE8 support, which we no longer support (see support for everything else here: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById).

In Action

- Also remove elementById since it was needed for IE8 support
Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

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

This looks good
Thanks!
Can this happen with other directives like clip paths? Should we igonre them as well?

@gloriousjob
Copy link
Contributor Author

gloriousjob commented Oct 22, 2023

I didn't realize that was being used by the use tag (elements_parser apparently handles this). But I found an example and tested it. It worked normally and when I changed the id to a bad one, it ignored the clipping so looks like the code is already healthy for that.
Only question I have now is how to get the 2 check failures to pass. I'm not sure if this is because I'm using my own repo since I don't have write access on the official repo.

@ShaMan123
Copy link
Contributor

I didn't realize that was being used by the use tag (elements_parser apparently handles this). But I found an example and tested it. It worked normally and when I changed the id to a bad one, it ignored the clipping so looks like the code is already healthy for that.

Could you add a test?

Only question I have now is how to get the 2 check failures to pass. I'm not sure if this is because I'm using my own repo since I don't have write access on the official repo.

You are right, it is because of write access.

@gloriousjob
Copy link
Contributor Author

Could you add a test?

Tacked on additional test.

test/unit/parser.js Outdated Show resolved Hide resolved
@asturur
Copy link
Member

asturur commented Oct 26, 2023

Do we have an svg with missing xlink and can we see how the browser renders it?

@gloriousjob
Copy link
Contributor Author

gloriousjob commented Oct 26, 2023

Do we have an svg with missing xlink and can we see how the browser renders it?

The svg from the unit test looks like (
Pretty simple but without the fix, nothing renders in fabric whereas it renders like this with the fix):
1

@asturur
Copy link
Member

asturur commented Oct 26, 2023

i moved the read shape into the defs element so we can test that the use element with the wrong clip-path still work without the clippath.
If the path is outside defs, you never know if the parser ignored the wrong clip-path attribute or ignored the whole <use> node

@asturur asturur changed the title Fix missing xlink target issue on svg parsing Fix(SVGParser) ignore missing xlink target issue on svg parsing Oct 26, 2023
@asturur
Copy link
Member

asturur commented Oct 26, 2023

@ShaMan123 i m merging this since is a good fix and we can push it up with the beta right away, ok?

@ShaMan123
Copy link
Contributor

sure

@asturur asturur merged commit edbef60 into fabricjs:master Oct 27, 2023
@gloriousjob gloriousjob deleted the ISSUE-9109-fix-cloneNode-in-svg-parse branch August 10, 2024 17:59
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.

[Bug]: Cannot read properties of undefined (reading 'cloneNode')
3 participants