Prefer URL constructor over url
dependency
This commit is contained in:
parent
9d45a3760f
commit
3b13eb7b44
3 changed files with 3 additions and 16 deletions
|
@ -25,7 +25,6 @@ import _linkifyElement from 'linkifyjs/element';
|
||||||
import _linkifyString from 'linkifyjs/string';
|
import _linkifyString from 'linkifyjs/string';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import EMOJIBASE_REGEX from 'emojibase-regex';
|
import EMOJIBASE_REGEX from 'emojibase-regex';
|
||||||
import url from 'url';
|
|
||||||
import katex from 'katex';
|
import katex from 'katex';
|
||||||
import { AllHtmlEntities } from 'html-entities';
|
import { AllHtmlEntities } from 'html-entities';
|
||||||
import { IContent } from 'matrix-js-sdk/src/models/event';
|
import { IContent } from 'matrix-js-sdk/src/models/event';
|
||||||
|
@ -153,10 +152,8 @@ export function getHtmlText(insaneHtml: string): string {
|
||||||
*/
|
*/
|
||||||
export function isUrlPermitted(inputUrl: string): boolean {
|
export function isUrlPermitted(inputUrl: string): boolean {
|
||||||
try {
|
try {
|
||||||
const parsed = url.parse(inputUrl);
|
|
||||||
if (!parsed.protocol) return false;
|
|
||||||
// URL parser protocol includes the trailing colon
|
// URL parser protocol includes the trailing colon
|
||||||
return PERMITTED_URL_SCHEMES.includes(parsed.protocol.slice(0, -1));
|
return PERMITTED_URL_SCHEMES.includes(new URL(inputUrl).protocol.slice(0, -1));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,8 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import url from 'url';
|
|
||||||
|
|
||||||
import SdkConfig from '../SdkConfig';
|
import SdkConfig from '../SdkConfig';
|
||||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||||
import { urlSearchParamsToObject } from "./UrlUtils";
|
|
||||||
|
|
||||||
export function getHostingLink(campaign) {
|
export function getHostingLink(campaign) {
|
||||||
const hostingLink = SdkConfig.get().hosting_signup_link;
|
const hostingLink = SdkConfig.get().hosting_signup_link;
|
||||||
|
@ -28,11 +25,8 @@ export function getHostingLink(campaign) {
|
||||||
if (MatrixClientPeg.get().getDomain() !== 'matrix.org') return null;
|
if (MatrixClientPeg.get().getDomain() !== 'matrix.org') return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const hostingUrl = url.parse(hostingLink);
|
const hostingUrl = new URL(hostingLink);
|
||||||
const params = urlSearchParamsToObject(new URLSearchParams(hostingUrl.query));
|
hostingUrl.searchParams.set("utm_campaign", campaign);
|
||||||
params.utm_campaign = campaign;
|
|
||||||
hostingUrl.search = undefined;
|
|
||||||
hostingUrl.query = params;
|
|
||||||
return hostingUrl.format();
|
return hostingUrl.format();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return hostingLink;
|
return hostingLink;
|
||||||
|
|
|
@ -16,10 +16,6 @@ limitations under the License.
|
||||||
|
|
||||||
import * as url from "url";
|
import * as url from "url";
|
||||||
|
|
||||||
export function urlSearchParamsToObject<T extends {}>(params: URLSearchParams) {
|
|
||||||
return <T>Object.fromEntries([...params.entries()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a url has no path component, etc. abbreviate it to just the hostname
|
* If a url has no path component, etc. abbreviate it to just the hostname
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue