Compare commits

...

9 Commits

Author SHA1 Message Date
Reinaldo Neto 75db91b5b8 ensureSecureProcotol 2023-03-06 19:47:07 -03:00
Reinaldo Neto fb47f8221f minor tweak 2023-03-01 12:11:02 -03:00
Reinaldo Neto 67811bb36b add unit test to addProtocol 2023-02-15 11:26:53 -03:00
Reinaldo Neto dbef194fff
Merge branch 'develop' into FIX-Links-do-not-work-if-protocol-is-not-set-in-URL-prefix 2023-02-14 19:15:00 -03:00
Reinaldo Neto a5eaca0bcc minor tweak 2023-02-08 20:11:30 -03:00
Reinaldo Neto 05dca20e8d replace double slashs 2023-02-08 19:39:22 -03:00
Reinaldo Neto c23fa663cc
Merge branch 'develop' into FIX-Links-do-not-work-if-protocol-is-not-set-in-URL-prefix 2023-02-08 18:31:35 -03:00
Debojyoti Singha 5a2a0e7c0f
Merge branch 'develop' into FIX-Links-do-not-work-if-protocol-is-not-set-in-URL-prefix 2022-10-25 12:46:32 +05:30
gitstart a65655beb7 [FIX] - Links do not work if protocol is not set in URL prefix 2022-10-25 07:13:52 +00:00
3 changed files with 32 additions and 1 deletions

View File

@ -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');
});
});

View File

@ -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;

View File

@ -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,