Fix for SvgUri and SvgCssUri crashing on non-existing svg files - #1503
Conversation
|
Good catch! I think is a good improvement |
|
It would be great to add this fix! :) |
|
I also still have this problem and is quite a critical one if you are not fully in charge of the svg code. Any updates on this one? |
|
@tomsnep If this fix is critical for you, you can add patch-package to your project, save the patch below as diff --git a/node_modules/react-native-svg/src/xml.tsx b/node_modules/react-native-svg/src/xml.tsx
index 828f104..a8fea26 100644
--- a/node_modules/react-native-svg/src/xml.tsx
+++ b/node_modules/react-native-svg/src/xml.tsx
@@ -124,7 +124,7 @@ export function SvgXml(props: XmlProps) {
export async function fetchText(uri: string) {
const response = await fetch(uri);
- return await response.text();
+ return response.ok ? await response.text() : null
}
export function SvgUri(props: UriProps) { |
|
why hasn't this library been updated for a long time |
|
I double-checked the code I think it would be even better to import React, {Component} from 'react';
import { SvgUri } from 'react-native-svg';
class Example extends Component {
state={
uri: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/xruby.svg',
}
render() {
return (
<>
<SvgUri width={100} onError={err => this.setState({uri: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg'})} height={100} uri={this.state.uri} />
</>
);
}
}What do you think of it? |
|
I will also change the target branch since now |
|
Yes, looks good. Note that component |
|
Yeah, I think it was missed in this commit: 3c32a6f. Could you make a PR with such change for |
Summary
Fix for interpreting an HTML error response as svg data, and then crash when this cannot be parsed as well formed XML
closes #1500
Test Plan
n/a
What's required for testing (prerequisites)?
Just a a clean project with the latest versions of react-native and react-native-svg
What are the steps to reproduce (after prerequisites)?
Include this in App.js
and you'll get:
Then make the file name invalid
and you'll get:
With the fix you'll get this instead:
Compatibility
Checklist
README.md__tests__folder