fix(rn,shared-video) validate URLs to avoid crashes on the native side

This commit is contained in:
Saúl Ibarra Corretgé 2021-09-14 12:23:40 +02:00 committed by Saúl Ibarra Corretgé
parent b92c1f52d5
commit 0b54e005d7
1 changed files with 16 additions and 2 deletions

View File

@ -66,10 +66,24 @@ export default class AbstractSharedVideoDialog<S: *> extends Component < Props,
return false; return false;
} }
const youtubeId = getYoutubeId(trimmedLink);
const { onPostSubmit } = this.props; const { onPostSubmit } = this.props;
const youtubeId = getYoutubeId(trimmedLink);
onPostSubmit(youtubeId || trimmedLink); if (youtubeId) {
onPostSubmit(youtubeId);
return true;
}
// Check if the URL is valid, native may crash otherwise.
try {
// eslint-disable-next-line no-new
new URL(trimmedLink);
} catch (_) {
return false;
}
onPostSubmit(trimmedLink);
return true; return true;
} }