aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/containers/settings/EditServiceScreen.js2
-rw-r--r--src/helpers/url-helpers.ts6
-rw-r--r--src/helpers/validation-helpers.ts21
3 files changed, 17 insertions, 12 deletions
diff --git a/src/containers/settings/EditServiceScreen.js b/src/containers/settings/EditServiceScreen.js
index b84c0d5bb..ef907dcb8 100644
--- a/src/containers/settings/EditServiceScreen.js
+++ b/src/containers/settings/EditServiceScreen.js
@@ -267,7 +267,7 @@ class EditServiceScreen extends Component {
267 Object.assign(config.fields, { 267 Object.assign(config.fields, {
268 customUrl: { 268 customUrl: {
269 label: intl.formatMessage(messages.customUrl), 269 label: intl.formatMessage(messages.customUrl),
270 placeholder: 'https://', 270 placeholder: "'http://' or 'https://' or 'file:///'",
271 value: service.customUrl || recipe.serviceURL, 271 value: service.customUrl || recipe.serviceURL,
272 validators: [required, url], 272 validators: [required, url],
273 }, 273 },
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts
index 135f06cbf..c1ca3ab25 100644
--- a/src/helpers/url-helpers.ts
+++ b/src/helpers/url-helpers.ts
@@ -1,7 +1,7 @@
1// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/ 1// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/
2 2
3import { URL } from 'url'; 3import { URL } from 'url';
4import { ensureDirSync } from 'fs-extra'; 4import { ensureDirSync, existsSync } from 'fs-extra';
5import { shell } from 'electron'; 5import { shell } from 'electron';
6 6
7import { ALLOWED_PROTOCOLS } from '../config'; 7import { ALLOWED_PROTOCOLS } from '../config';
@@ -23,6 +23,10 @@ export function isValidExternalURL(url: string | URL) {
23 return isAllowed; 23 return isAllowed;
24} 24}
25 25
26export function isValidFileUrl(path: string) {
27 return path.startsWith('file') && existsSync(new URL(path));
28}
29
26export async function openPath(folderName: string) { 30export async function openPath(folderName: string) {
27 ensureDirSync(folderName); 31 ensureDirSync(folderName);
28 shell.openPath(folderName); 32 shell.openPath(folderName);
diff --git a/src/helpers/validation-helpers.ts b/src/helpers/validation-helpers.ts
index 23c297443..dfaf199ee 100644
--- a/src/helpers/validation-helpers.ts
+++ b/src/helpers/validation-helpers.ts
@@ -1,5 +1,6 @@
1import { defineMessages } from 'react-intl'; 1import { defineMessages } from 'react-intl';
2import isEmail from 'validator/lib/isEmail'; 2import isEmail from 'validator/lib/isEmail';
3import { isValidExternalURL, isValidFileUrl } from './url-helpers';
3 4
4const messages = defineMessages({ 5const messages = defineMessages({
5 required: { 6 required: {
@@ -47,17 +48,17 @@ export function email({ field }) {
47 48
48export function url({ field }) { 49export function url({ field }) {
49 const value = field.value.trim(); 50 const value = field.value.trim();
50 let isValid = false; 51 let isValid = true;
51 52
52 isValid = 53 if (value !== '') {
53 value !== '' 54 if (value.startsWith('http')) {
54 ? Boolean( 55 isValid = isValidExternalURL(value);
55 // eslint-disable-next-line unicorn/better-regex 56 } else if (value.startsWith('file')) {
56 /(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i.test( 57 isValid = isValidFileUrl(value);
57 value, 58 } else {
58 ), 59 isValid = false;
59 ) 60 }
60 : true; 61 }
61 62
62 return [ 63 return [
63 isValid, 64 isValid,