Merge pull request #3329 from dpalou/MOBILE-4097
MOBILE-4097 core: Don't convert to address URL if it's already a URLmain
commit
0df9f3651b
|
@ -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);
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue