base64 images with newlines will not work in some situations (many? most? all?), e.g. the React Native Share() library won't accept it properly as a url param.
<QRCode
getRef={c => {
if (!c?.toDataURL) return;
c?.toDataURL((base64Image: string) => {
// must strip whitespace due to 'bug' in QR code library
// see https://github.com/react-native-share/react-native-share/issues/1393#issuecomment-1568365217
base64QrCodeRef.current = base64Image.replace(/(\r\n|\n|\r)/gm, '');
});
}}
{...rest}
/>
Proposed fix:
Strip newlines from base64 output, i.e. append .replace(/(\r\n|\n|\r)/gm, '') to the return value of toDataURL().
base64 images with newlines will not work in some situations (many? most? all?), e.g. the React Native
Share()
library won't accept it properly as aurl
param.FAILURE CASE
SUCCESS CASE via https://github.com/react-native-share/react-native-share/issues/1393#issuecomment-1568365217
Proposed fix: Strip newlines from base64 output, i.e. append
.replace(/(\r\n|\n|\r)/gm, '')
to the return value oftoDataURL()
.