escape special characters in the regex replace call for the encoded path

This commit is contained in:
Akinwale Ariwodola 2018-08-27 08:29:29 +01:00
parent 94f9ad6cc4
commit fc572e237e

View file

@ -30,6 +30,7 @@ class MediaPlayer extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
encodedFilePath: null,
rate: 1,
volume: 1,
muted: false,
@ -284,9 +285,18 @@ class MediaPlayer extends React.PureComponent {
}
getEncodedDownloadPath = (fileInfo) => {
if (this.state.encodedFilePath) {
return this.state.encodedFilePath;
}
const { file_name: fileName } = fileInfo;
const encodedFileName = encodeURIComponent(fileName).replace(/!/g, '%21');
return fileInfo.download_path.replace(new RegExp(fileName, 'g'), encodedFileName);
const re = new RegExp(fileName.replace(/\-/g, '\\-')
.replace(/\(/g, '\\(')
.replace(/\)/g, '\\)'), 'g');
const encodedFilePath = fileInfo.download_path.replace(re, encodedFileName);
this.setState({ encodedFilePath });
return encodedFilePath;
}
render() {