MOBILE-4097 core: Don't convert to address URL if it's already a URL

main
Dani Palou 2022-06-21 15:48:34 +02:00
parent 34a987ae2a
commit fcf82349cf
2 changed files with 17 additions and 0 deletions

View File

@ -76,6 +76,16 @@ describe('CoreTextUtilsProvider', () => {
expect(CoreApp.isAndroid).toHaveBeenCalled(); expect(CoreApp.isAndroid).toHaveBeenCalled();
}); });
it('doesn\'t build address if it\'s already a URL', () => {
const address = 'https://moodle.org';
const url = textUtils.buildAddressURL(address);
expect(url).toEqual(address);
expect(DomSanitizer.bypassSecurityTrustUrl).toHaveBeenCalled();
});
it('matches glob patterns', () => { it('matches glob patterns', () => {
expect(textUtils.matchesGlob('/foo/bar', '/foo/bar')).toBe(true); expect(textUtils.matchesGlob('/foo/bar', '/foo/bar')).toBe(true);
expect(textUtils.matchesGlob('/foo/bar', '/foo/bar/')).toBe(false); expect(textUtils.matchesGlob('/foo/bar', '/foo/bar/')).toBe(false);

View File

@ -25,6 +25,7 @@ import { CoreViewerTextComponent } from '@features/viewer/components/text/text';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreDomUtils } from './dom'; import { CoreDomUtils } from './dom';
import { CoreText } from '@singletons/text'; import { CoreText } from '@singletons/text';
import { CoreUrl } from '@singletons/url';
/** /**
* Different type of errors the app can treat. * Different type of errors the app can treat.
@ -155,6 +156,12 @@ export class CoreTextUtilsProvider {
* @return URL to view the address. * @return URL to view the address.
*/ */
buildAddressURL(address: string): SafeUrl { buildAddressURL(address: string): SafeUrl {
const parsedUrl = CoreUrl.parse(address);
if (parsedUrl?.protocol) {
// It's already a URL, don't convert it.
return DomSanitizer.bypassSecurityTrustUrl(address);
}
return DomSanitizer.bypassSecurityTrustUrl((CoreApp.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + return DomSanitizer.bypassSecurityTrustUrl((CoreApp.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') +
encodeURIComponent(address)); encodeURIComponent(address));
} }