MOBILE-4640 url: Fix detect revision from tokenpluginfile URLs
This commit is contained in:
		
							parent
							
								
									54100ac7e6
								
							
						
					
					
						commit
						e181137a6a
					
				@ -316,12 +316,12 @@ describe('CoreUrl singleton', () => {
 | 
				
			|||||||
            .toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
 | 
					            .toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
 | 
				
			||||||
        expect(CoreUrl.getPluginFileArgs('http://mysite.com/webservice/pluginfile.php/6/mod_foo/content/14/foo.txt'))
 | 
					        expect(CoreUrl.getPluginFileArgs('http://mysite.com/webservice/pluginfile.php/6/mod_foo/content/14/foo.txt'))
 | 
				
			||||||
            .toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
 | 
					            .toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
 | 
				
			||||||
 | 
					        expect(CoreUrl.getPluginFileArgs('http://mysite.com/tokenpluginfile.php/abcdef123456/6/mod_foo/content/14/foo.txt'))
 | 
				
			||||||
 | 
					        .toEqual(['6', 'mod_foo', 'content', '14', 'foo.txt']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // It doesn't work with tokenpluginfile or other URLs, and also when pluginfile doesn't have enough params.
 | 
					        // It doesn't work with other URLs, and also when pluginfile doesn't have enough params.
 | 
				
			||||||
        expect(CoreUrl.getPluginFileArgs('http://mysite.com')).toEqual(undefined);
 | 
					        expect(CoreUrl.getPluginFileArgs('http://mysite.com')).toEqual(undefined);
 | 
				
			||||||
        expect(CoreUrl.getPluginFileArgs('http://mysite.com/pluginfile.php/6/')).toEqual(undefined);
 | 
					        expect(CoreUrl.getPluginFileArgs('http://mysite.com/pluginfile.php/6/')).toEqual(undefined);
 | 
				
			||||||
        expect(CoreUrl.getPluginFileArgs('http://mysite.com/tokenpluginfile.php/abcdef123456/6/mod_foo/content/14/foo.txt'))
 | 
					 | 
				
			||||||
            .toEqual(undefined);
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -693,19 +693,22 @@ export class CoreUrl {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Return the array of arguments of the pluginfile url.
 | 
					     * Return the array of arguments of the pluginfile or tokenpluginfile url.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param url URL to get the args.
 | 
					     * @param url URL to get the args.
 | 
				
			||||||
     * @returns The args found, undefined if not a pluginfile.
 | 
					     * @returns The args found, undefined if not a pluginfile.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    static getPluginFileArgs(url: string): string[] | undefined {
 | 
					    static getPluginFileArgs(url: string): string[] | undefined {
 | 
				
			||||||
        if (!CoreUrl.isPluginFileUrl(url)) {
 | 
					        let args: string[] = [];
 | 
				
			||||||
            // Not pluginfile, return.
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (CoreUrl.isPluginFileUrl(url)) {
 | 
				
			||||||
            const relativePath = url.substring(url.indexOf('/pluginfile.php') + 16);
 | 
					            const relativePath = url.substring(url.indexOf('/pluginfile.php') + 16);
 | 
				
			||||||
        const args = relativePath.split('/');
 | 
					            args = relativePath.split('/');
 | 
				
			||||||
 | 
					        } else if (CoreUrl.isTokenPluginFileUrl(url)) {
 | 
				
			||||||
 | 
					            const relativePath = url.substring(url.indexOf('/tokenpluginfile.php') + 21);
 | 
				
			||||||
 | 
					            args = relativePath.split('/');
 | 
				
			||||||
 | 
					            args.shift(); // Remove the token.
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (args.length < 3) {
 | 
					        if (args.length < 3) {
 | 
				
			||||||
            // To be a plugin file it should have at least contextId, Component and Filearea.
 | 
					            // To be a plugin file it should have at least contextId, Component and Filearea.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user