Skip to content

Commit e181137

Browse files
committed
MOBILE-4640 url: Fix detect revision from tokenpluginfile URLs
1 parent 54100ac commit e181137

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/core/singletons/tests/url.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ describe('CoreUrl singleton', () => {
316316
.toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
317317
expect(CoreUrl.getPluginFileArgs('http://mysite.com/webservice/pluginfile.php/6/mod_foo/content/14/foo.txt'))
318318
.toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
319+
expect(CoreUrl.getPluginFileArgs('http://mysite.com/tokenpluginfile.php/abcdef123456/6/mod_foo/content/14/foo.txt'))
320+
.toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
319321

320-
// It doesn't work with tokenpluginfile or other URLs, and also when pluginfile doesn't have enough params.
322+
// It doesn't work with other URLs, and also when pluginfile doesn't have enough params.
321323
expect(CoreUrl.getPluginFileArgs('http://mysite.com')).toEqual(undefined);
322324
expect(CoreUrl.getPluginFileArgs('http://mysite.com/pluginfile.php/6/')).toEqual(undefined);
323-
expect(CoreUrl.getPluginFileArgs('http://mysite.com/tokenpluginfile.php/abcdef123456/6/mod_foo/content/14/foo.txt'))
324-
.toEqual(undefined);
325325
});
326326

327327
});

src/core/singletons/url.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,19 +693,22 @@ export class CoreUrl {
693693
}
694694

695695
/**
696-
* Return the array of arguments of the pluginfile url.
696+
* Return the array of arguments of the pluginfile or tokenpluginfile url.
697697
*
698698
* @param url URL to get the args.
699699
* @returns The args found, undefined if not a pluginfile.
700700
*/
701701
static getPluginFileArgs(url: string): string[] | undefined {
702-
if (!CoreUrl.isPluginFileUrl(url)) {
703-
// Not pluginfile, return.
704-
return;
705-
}
702+
let args: string[] = [];
706703

707-
const relativePath = url.substring(url.indexOf('/pluginfile.php') + 16);
708-
const args = relativePath.split('/');
704+
if (CoreUrl.isPluginFileUrl(url)) {
705+
const relativePath = url.substring(url.indexOf('/pluginfile.php') + 16);
706+
args = relativePath.split('/');
707+
} else if (CoreUrl.isTokenPluginFileUrl(url)) {
708+
const relativePath = url.substring(url.indexOf('/tokenpluginfile.php') + 21);
709+
args = relativePath.split('/');
710+
args.shift(); // Remove the token.
711+
}
709712

710713
if (args.length < 3) {
711714
// To be a plugin file it should have at least contextId, Component and Filearea.

0 commit comments

Comments
 (0)