[FIX] Encode Image URI (#1909)
* [FIX] Encode Image URI * [FIX] Check if Image is Valid Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
87724ae6d4
commit
ce1a2d5374
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
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);
|
||||
};
|
Loading…
Reference in New Issue