Uri encode filenames with spaces for the media player #229

Merged
akinwale merged 1 commit from uri-encode-paths into master 2018-08-14 08:51:05 +02:00

View file

@ -261,6 +261,12 @@ class MediaPlayer extends React.PureComponent {
return null;
}
getEncodedDownloadPath = (fileInfo) => {
const { file_name: fileName } = fileInfo;
const encodedFileName = encodeURIComponent(fileName).replace(/!/g, '%21');
skhameneh commented 2018-08-14 06:27:35 +02:00 (Migrated from github.com)
Review

The entire set of unescaped characters is -_.!~*'(), does this need to reflect that?

The entire set of unescaped characters is `-_.!~*'()`, does this need to reflect that?
akinwale commented 2018-08-14 08:50:51 +02:00 (Migrated from github.com)
Review

Not necessarily. The rest of the characters can be left as is in the filename, but if we have to escape any of them in the future, we could just add an additional replace call here.

Not necessarily. The rest of the characters can be left as is in the filename, but if we have to escape any of them in the future, we could just add an additional `replace` call here.
return fileInfo.download_path.replace(new RegExp(fileName, 'g'), encodedFileName);
}
render() {
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth;
@ -279,7 +285,7 @@ class MediaPlayer extends React.PureComponent {
return (
<View style={styles} onLayout={onLayout}>
<Video source={{ uri: 'file:///' + fileInfo.download_path }}
<Video source={{ uri: 'file:///' + this.getEncodedDownloadPath(fileInfo) }}
ref={(ref: Video) => { this.video = ref }}
resizeMode={this.state.resizeMode}
playInBackground={backgroundPlayEnabled}