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

SvgUri/SvgFromXml components don't un-escape special symbols #2411

Open
DanilaFadeev opened this issue Aug 14, 2024 · 1 comment
Open

SvgUri/SvgFromXml components don't un-escape special symbols #2411

DanilaFadeev opened this issue Aug 14, 2024 · 1 comment

Comments

@DanilaFadeev
Copy link

DanilaFadeev commented Aug 14, 2024

Description

The SvgUri and its underlying SvgFromXml component do not un-escape text from the SVG element. It prevents displaying special characters (such as <, >, &, and others) in SVG text elements.

Example

Source SVG string, retrieved from remote URL:

<svg>
    <text x="10" y="32" fontSize="32">&amp; &lt; &gt;</text>
</svg>

React Native SVG component example:

import { SafeAreaView, StyleSheet } from 'react-native';
import { SvgFromXml } from "react-native-svg";

export default function App() {
  return (
    <SafeAreaView>
      <SvgFromXml
        xml={`<svg><text x="10" y="32" fontSize="32">&amp; &lt; &gt;</text></svg>`}
      />
    </SafeAreaView>
  );
}

Result

IOS Android Web
Screenshot 2024-08-14 at 13 06 28 Screenshot 2024-08-14 at 13 08 13 Screenshot 2024-08-14 at 13 09 13

Expected behavior

The HTML special characters should be un-escaped inside the tag at the SVG rendering time, as it works on a web browser.

Steps to reproduce

Can be reproduced using a base React Native or Expo project.

Snack or a link to a repository

https://snack.expo.dev/@danilademidovich/23ac00?platform=ios

SVG version

15.2.0

React Native version

0.74.1

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo Go

Architecture

None

Build type

Release app & dev bundle

Device

None

Device model

iPhone 14 Pro Max

Acknowledgements

Yes

@github-actions github-actions bot added Missing info The user didn't precise the problem enough Repro provided and removed Missing info The user didn't precise the problem enough labels Aug 14, 2024
@bohdanprog
Copy link
Member

Hi @DanilaFadeev,

Thank you for your contribution to the library's development. I believe the optimal solution at this point is to display SVG using SVG components as we work on enhancing our parsing function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants