Skip to content

SvgUri Error. UnexpectedData 
		 #1199

Closed
@dimaportenko

Description

Bug

I'm using SvgUri like

<SvgUri
	width="60"
	height="60"
	uri="https://mydomain.com/images/logo.svg"
/>

and I'm getting following error
Screen Shot 2019-11-20 at 6 04 10 PM

there is element in SVG file

<polygon fill="#FF4422" points="37.16667,56.13386 47.16667,56.13386 47.16667,81.13386 62.16665,81.13386 62.16665,56.13386 &#10;&#9;&#9;72.16666,56.13386 72.16666,41.13386 37.16667,41.13386 &#9;"/>

and issue causes following escape format sequences &#10;, &#9;

I've tried to put this string directly to Polygon elements and it unescaped those sequences automatically and render just fine. Also, my SVG renders in a browser without any issue.

<Polygon
  points="37.16667,56.13386 47.16667,56.13386 47.16667,81.13386 62.16665,81.13386 62.16665,56.13386 &#10;&#9;&#9;72.16666,56.13386 72.16666,41.13386 37.16667,41.13386 &#9;"
  fill="#FF4422"
/>

I see solution as add

.replace(/&#.+?;/g, '')

to unescape fetched string. I think best place is

// src/xml.tsx

function getAttributes(props: {
  [x: string]: Styles | string | number | boolean | undefined;
  style?: string | Styles | undefined;
}) {
  while (i < length) {
    
    // ...
    
    // ----- fix starts
    if (typeof value === "string") {
      value = String(value).replace(/&#.+?;/g, '');
    }
    // ----- fix ends

    props[camelCase(name)] = value;
  }
}

I can make PR. Please let me know what do you think.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions