diff --git a/app/containers/markdown/index.tsx b/app/containers/markdown/index.tsx index d4876ba04..6d42e960c 100644 --- a/app/containers/markdown/index.tsx +++ b/app/containers/markdown/index.tsx @@ -16,7 +16,7 @@ import MarkdownTableRow from './TableRow'; import MarkdownTableCell from './TableCell'; import mergeTextNodes from './mergeTextNodes'; import styles from './styles'; -import { isValidURL } from '../../lib/methods/helpers/url'; +import { isValidUrl } from '../../lib/methods/helpers/isValidUrl'; import NewMarkdown from './new'; import { formatText } from './formatText'; import { IUserMention, IUserChannel, TOnLinkPress } from './interfaces'; @@ -246,7 +246,7 @@ class Markdown extends PureComponent { }; renderImage = ({ src }: { src: string }) => { - if (!isValidURL(src)) { + if (!isValidUrl(src)) { return null; } diff --git a/app/lib/methods/helpers/index.ts b/app/lib/methods/helpers/index.ts index 4284fbc92..acf8b8e38 100644 --- a/app/lib/methods/helpers/index.ts +++ b/app/lib/methods/helpers/index.ts @@ -11,7 +11,7 @@ export * from './isReadOnly'; export * from './media'; export * from './room'; export * from './server'; -export * from './url'; +export * from './isSsl'; export * from './isValidEmail'; export * from './random'; export * from './image'; diff --git a/app/lib/methods/helpers/isSsl.ts b/app/lib/methods/helpers/isSsl.ts new file mode 100644 index 000000000..2de3d1393 --- /dev/null +++ b/app/lib/methods/helpers/isSsl.ts @@ -0,0 +1,2 @@ +// Use checkUseSsl: false only if server url starts with http:// +export const isSsl = (url: string): boolean => !/http:\/\//.test(url); diff --git a/app/lib/methods/helpers/url.ts b/app/lib/methods/helpers/url.ts deleted file mode 100644 index efe675b7e..000000000 --- a/app/lib/methods/helpers/url.ts +++ /dev/null @@ -1,15 +0,0 @@ -export const isValidURL = (url: string): boolean => { - const pattern = new RegExp( - '^(https?:\\/\\/)?' + // protocol - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name - '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path - '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string - '(\\#[-a-z\\d_]*)?$', - 'i' - ); // fragment locator - return !!pattern.test(url); -}; - -// Use checkUseSsl: false only if server url starts with http:// -export const isSsl = (url: string): boolean => !/http:\/\//.test(url); diff --git a/app/lib/services/sdk.ts b/app/lib/services/sdk.ts index e6b89121d..0bfe8d250 100644 --- a/app/lib/services/sdk.ts +++ b/app/lib/services/sdk.ts @@ -3,7 +3,7 @@ import EJSON from 'ejson'; import isEmpty from 'lodash/isEmpty'; import { twoFactor } from './twoFactor'; -import { isSsl } from '../methods/helpers/url'; +import { isSsl } from '../methods/helpers/isSsl'; import { store as reduxStore } from '../store/auxStore'; import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../definitions/rest/helpers'; import { compareServerVersion, random } from '../methods/helpers';