diff --git a/apps/test-examples/index.tsx b/apps/test-examples/index.tsx
index 20997ac8e..bbf8a1151 100644
--- a/apps/test-examples/index.tsx
+++ b/apps/test-examples/index.tsx
@@ -17,6 +17,7 @@ import Test2071 from './src/Test2071';
import Test2080 from './src/Test2080';
import Test2086 from './src/Test2086';
import Test2089 from './src/Test2089';
+import Test2142 from './src/Test2142';
import Test2148 from './src/Test2148';
import Test2196 from './src/Test2196';
import Test2248 from './src/Test2248';
diff --git a/apps/test-examples/src/Test2142.tsx b/apps/test-examples/src/Test2142.tsx
new file mode 100644
index 000000000..0396a24a2
--- /dev/null
+++ b/apps/test-examples/src/Test2142.tsx
@@ -0,0 +1,22 @@
+import {SvgUri} from 'react-native-svg';
+
+export default function App() {
+ return (
+ <>
+
+
+
+
+ >
+ );
+}
diff --git a/src/utils/fetchData.ts b/src/utils/fetchData.ts
index f08b16ed2..d141be31c 100644
--- a/src/utils/fetchData.ts
+++ b/src/utils/fetchData.ts
@@ -1,4 +1,5 @@
import { Platform } from 'react-native';
+import { Buffer } from 'buffer';
export async function fetchText(uri?: string): Promise {
if (!uri) {
@@ -6,11 +7,22 @@ export async function fetchText(uri?: string): Promise {
}
if (uri.startsWith('data:image/svg+xml;utf8') && Platform.OS === 'android') {
return dataUriToXml(uri);
+ } else if (uri.startsWith('data:image/svg+xml;base64')) {
+ return decodeBase64Image(uri);
} else {
return fetchUriData(uri);
}
}
+const decodeBase64Image = (uri: string) => {
+ const decoded = decodeURIComponent(uri);
+ const splitContent = decoded.split(';')[1].split(',');
+ const dataType = splitContent[0] as BufferEncoding;
+ const content = splitContent.slice(1).join(',');
+
+ return Buffer.from(content, dataType).toString('utf-8');
+};
+
function dataUriToXml(uri: string): string | null {
try {
// decode and remove data:image/svg+xml;utf8, prefix