Skip to content
Snippets Groups Projects
Unverified Commit ce1a2d53 authored by Djorkaeff Alexandre's avatar Djorkaeff Alexandre Committed by GitHub
Browse files

[FIX] Encode Image URI (#1909)


* [FIX] Encode Image URI

* [FIX] Check if Image is Valid

Co-authored-by: default avatarDiego Mello <diegolmello@gmail.com>
parent 87724ae6
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ import MarkdownTableCell from './TableCell';
import mergeTextNodes from './mergeTextNodes';
import styles from './styles';
import { isValidURL } from '../../utils/url';
// Support <http://link|Text>
const formatText = text => text.replace(
......@@ -278,7 +279,18 @@ class Markdown extends PureComponent {
);
}
renderImage = ({ src }) => <Image style={styles.inlineImage} source={{ uri: src }} />;
renderImage = ({ src }) => {
if (!isValidURL(src)) {
return null;
}
return (
<Image
style={styles.inlineImage}
source={{ uri: encodeURI(src) }}
/>
);
}
renderEditedIndicator = () => {
const { theme } = this.props;
......
export const isValidURL = (url) => {
const pattern = new RegExp('^(https?:\\/\\/)?' // protocol
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' // domain name
+ '((\\d{1,3}\\.){3}\\d{1,3}))' // OR ip (v4) address
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' // port and path
+ '(\\?[;&a-z\\d%_.~+=-]*)?' // query string
+ '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return !!pattern.test(url);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment