Parsing error with xmlns:x specified

Open
#795 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
objective-c

Research direction

Reproduce the provided SVG and start in SVGSVGElement:postProcessAttributesAddingErrorsTo, then inspect NamedNodeMap:getNamedItem where the x attribute is selected. Confirm namespace-qualified attributes do not cause the SVG x value to resolve to the xmlns:x URL, and add a regression test or verification for successful parsing without the reported fatal conversion error.

Written by the indexing model from the issue text.

Description

New Issue Checklist
  • I have read and understood the CONTRIBUTING guide
  • I have reproduced the problem while running in Xcode, and read the Console log, and acted upon any relevant error or warning messages
  • I have reproduced the problem while running in Xcode's Debugger, and used breakpoints to examine the actual values of variables vs the expected values
  • I am not using CocoaPods, or: I am using CocoaPods, but have verified my podspec points to SVGKit v2.x
Issue Description and Steps

When parsing the following SVG (only relevant part copied below)

<?xml version="1.0"?>
<svg xmlns:x="http://ns.adobe.com/Extensibility/1.0/" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="Layer_1" x="0px" y="0px" width="1440px" height="1440px" viewBox="0 0 1440 1440" xml:space="preserve">
</svg>

the resulting UIImage is nil. This is due to the fact that in SVGSVGElement:postProcessAttributesAddingErrorsTo the x position is parsed incorrectly. The returned NSString from this call:
NSString* pos_x = [self getAttribute:@"x"]; is http://ns.adobe.com/Extensibility/1.0/ and not 0px. I verified that in NamedNodeMap:getNamedItem there are three dictionaries one for https://www.w3.org/2000/xmIns/ and another one for https://www.w3.org/2000/svg. Only the latter contains the correct x value. However since https://www.w3.org/2000/xmIns/ is the first item in the list its x value is retrieved and then parsing this string to a number fails with the following error:

Printing description of self->parseErrorsAndWarnings:
[Parse result: 0 warnings, 0 errors(recoverable), 1 errors (fatal). First fatal error: Error Domain=SVGK Parsing Code=32523432 "Exception = Asked to convert a (19) value to a (5) (couldn't find a valid conversion route). Float (4 d.p.) = 0.0000, String = http://ns.adobe.com/Extensibility/1.0/" UserInfo={NSLocalizedDescription=Exception = Asked to convert a (19) value to a (5) (couldn't find a valid conversion route). Float (4 d.p.) = 0.0000, String = http://ns.adobe.com/Extensibility/1.0/}

I am wondering: is this a bug in the library or is the SVG not correctly authored. Anyway there might be a better solution to this instead of bailing out. I am happy to hear your thoughts.

Kind regards,
David

PS: I attached a screenshots of the debugger displaying the problem.
Bildschirmfoto 2023-08-09 um 11 04 34
Bildschirmfoto 2023-08-09 um 10 45 30

Dominant language
Objective-C
Stars
4.6k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SVGKit/SVGKit

All issues in SVGKit/SVGKit

Similar issues

More Objective-C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.