Compare commits
9 Commits
develop
...
FIX-Links-
Author | SHA1 | Date |
---|---|---|
Reinaldo Neto | 75db91b5b8 | |
Reinaldo Neto | fb47f8221f | |
Reinaldo Neto | 67811bb36b | |
Reinaldo Neto | dbef194fff | |
Reinaldo Neto | a5eaca0bcc | |
Reinaldo Neto | 05dca20e8d | |
Reinaldo Neto | c23fa663cc | |
Debojyoti Singha | 5a2a0e7c0f | |
gitstart | a65655beb7 |
|
@ -0,0 +1,20 @@
|
|||
import ensureSecureProtocol from './ensureSecureProtocol';
|
||||
|
||||
describe('Add the protocol https at the begin of the URL', () => {
|
||||
it('return the link as original when sent with https at the begin', () => {
|
||||
const linkHttps = 'https://www.google.com';
|
||||
expect(ensureSecureProtocol(linkHttps)).toBe(linkHttps);
|
||||
});
|
||||
it('return the link as original when sent with http at the begin', () => {
|
||||
const linkHttp = 'http://www.google.com';
|
||||
expect(ensureSecureProtocol(linkHttp)).toBe(linkHttp);
|
||||
});
|
||||
it("return a new link with protocol at the begin when there isn't the protocol at the begin", () => {
|
||||
const linkWithoutProtocol = 'www.google.com';
|
||||
expect(ensureSecureProtocol(linkWithoutProtocol)).toBe('https://www.google.com');
|
||||
});
|
||||
it('return the link correctly when the original starts with double slash, because the server is returning that', () => {
|
||||
const linkWithDoubleSlashAtBegin = '//www.google.com';
|
||||
expect(ensureSecureProtocol(linkWithDoubleSlashAtBegin)).toBe('https://www.google.com');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
// If the link does not have the protocol at the beginning, we are inserting https as the default,
|
||||
// since by convention the most used is the secure protocol, with the same behavior as the web.
|
||||
const ensureSecureProtocol = (url: string): string => {
|
||||
if (!url.toLowerCase().startsWith('http')) {
|
||||
return `https://${url.replace('//', '')}`;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
export default ensureSecureProtocol;
|
|
@ -5,6 +5,7 @@ import parse from 'url-parse';
|
|||
import { themes } from '../../constants';
|
||||
import { TSupportedThemes } from '../../../theme';
|
||||
import UserPreferences from '../userPreferences';
|
||||
import ensureSecureProtocol from './ensureSecureProtocol';
|
||||
|
||||
export const DEFAULT_BROWSER_KEY = 'DEFAULT_BROWSER_KEY';
|
||||
|
||||
|
@ -37,9 +38,9 @@ const appSchemeURL = (url: string, browser: string): string => {
|
|||
};
|
||||
|
||||
const openLink = async (url: string, theme: TSupportedThemes = 'light'): Promise<void> => {
|
||||
url = ensureSecureProtocol(url);
|
||||
try {
|
||||
const browser = UserPreferences.getString(DEFAULT_BROWSER_KEY);
|
||||
|
||||
if (browser === 'inApp') {
|
||||
await WebBrowser.openBrowserAsync(url, {
|
||||
toolbarColor: themes[theme].headerBackground,
|
||||
|
|
Loading…
Reference in New Issue