Merge pull request #4236 from dpalou/MOBILE-4688
MOBILE-4688 file: Fix files with unencoded % in their namemain
commit
a5cec5860c
|
@ -149,7 +149,19 @@ export class CoreFileProvider {
|
||||||
await this.init();
|
await this.init();
|
||||||
this.logger.debug('Get file: ' + path);
|
this.logger.debug('Get file: ' + path);
|
||||||
|
|
||||||
return <FileEntry> await File.resolveLocalFilesystemUrl(this.addBasePathIfNeeded(path));
|
try {
|
||||||
|
return <FileEntry> await File.resolveLocalFilesystemUrl(this.addBasePathIfNeeded(path));
|
||||||
|
} catch (error) {
|
||||||
|
if (error && error.code === FileError.NOT_FOUND_ERR) {
|
||||||
|
// Cannot read some files if the path contains the % character and it's not an encoded char. Try encoding it.
|
||||||
|
const encodedPath = encodeURI(path);
|
||||||
|
if (encodedPath !== path) {
|
||||||
|
return <FileEntry> await File.resolveLocalFilesystemUrl(this.addBasePathIfNeeded(encodedPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +175,19 @@ export class CoreFileProvider {
|
||||||
|
|
||||||
this.logger.debug('Get directory: ' + path);
|
this.logger.debug('Get directory: ' + path);
|
||||||
|
|
||||||
return await File.resolveDirectoryUrl(this.addBasePathIfNeeded(path));
|
try {
|
||||||
|
return await File.resolveDirectoryUrl(this.addBasePathIfNeeded(path));
|
||||||
|
} catch (error) {
|
||||||
|
if (error && error.code === FileError.NOT_FOUND_ERR) {
|
||||||
|
// Cannot read some files if the path contains the % character and it's not an encoded char. Try encoding it.
|
||||||
|
const encodedPath = encodeURI(path);
|
||||||
|
if (encodedPath !== path) {
|
||||||
|
return await File.resolveDirectoryUrl(this.addBasePathIfNeeded(encodedPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -828,7 +852,19 @@ export class CoreFileProvider {
|
||||||
|
|
||||||
return <FileEntry | DirectoryEntry> entry;
|
return <FileEntry | DirectoryEntry> entry;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// The copy can fail if the path has encoded characters. Try again if that's the case.
|
try {
|
||||||
|
// The copy/move can fail if the final path contains the % character and it's not an encoded char. Try encoding it.
|
||||||
|
const encodedTo = encodeURI(to);
|
||||||
|
if (to !== encodedTo) {
|
||||||
|
const entry = await moveCopyFn(this.basePath, from, this.basePath, encodedTo);
|
||||||
|
|
||||||
|
return <FileEntry | DirectoryEntry> entry;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Still failing, continue with next fallback.
|
||||||
|
}
|
||||||
|
|
||||||
|
// The copy/move can fail if the path has encoded characters. Try again if that's the case.
|
||||||
const decodedFrom = decodeURI(from);
|
const decodedFrom = decodeURI(from);
|
||||||
const decodedTo = decodeURI(to);
|
const decodedTo = decodeURI(to);
|
||||||
|
|
||||||
|
|
|
@ -128,17 +128,27 @@ export class CoreOpener {
|
||||||
// Error, use the original path.
|
// Error, use the original path.
|
||||||
}
|
}
|
||||||
|
|
||||||
const openFile = async (mimetype?: string) => {
|
const openFile = async (path: string, mimetype?: string) => {
|
||||||
if (CoreOpener.shouldOpenWithDialog(options)) {
|
try {
|
||||||
await FileOpener.showOpenWithDialog(path, mimetype || '');
|
if (CoreOpener.shouldOpenWithDialog(options)) {
|
||||||
} else {
|
await FileOpener.showOpenWithDialog(path, mimetype || '');
|
||||||
await FileOpener.open(path, mimetype || '');
|
} else {
|
||||||
|
await FileOpener.open(path, mimetype || '');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// If the file contains the % character without encoding the open can fail. Try again encoding it.
|
||||||
|
const encodedPath = encodeURI(path);
|
||||||
|
if (path !== encodedPath) {
|
||||||
|
return await openFile(encodedPath, mimetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
await openFile(mimetype);
|
await openFile(path, mimetype);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!extension || !error || Number(error.status) !== 9) {
|
if (!extension || !error || Number(error.status) !== 9) {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -150,7 +160,7 @@ export class CoreOpener {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
await openFile(deprecatedMimetype);
|
await openFile(path, deprecatedMimetype);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreOpener.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype);
|
CoreOpener.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype);
|
||||||
|
|
Loading…
Reference in New Issue