Skip to content

fix: use url-parse for url construction #15670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 27, 2024
19 changes: 16 additions & 3 deletions offlinedocs/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "@chakra-ui/react";
import fm from "front-matter";
import { readFileSync } from "fs";
import _ from "lodash";
import _, { min } from "lodash";
import { GetStaticPaths, GetStaticProps, NextPage } from "next";
import Head from "next/head";
import NextLink from "next/link";
Expand Down Expand Up @@ -194,8 +194,21 @@ const getNavigation = (manifest: Manifest): Nav => {
return navigation;
};

const removeHtmlComments = (string: string) => {
return string.replace(/<!--[\s\S]*?-->/g, "");
const removeHtmlComments = (input: string) => {
if (!input) return "";

let lastResult = input;
let currentResult = "";

// Keep replacing until no more changes occur
do {
currentResult = lastResult.replace(/<!--[\s\S]*?-->/g, "");
if (currentResult === lastResult) {
break;
}
lastResult = currentResult;
} while (true);
return currentResult;
};

export const getStaticPaths: GetStaticPaths = () => {
Expand Down
18 changes: 9 additions & 9 deletions offlinedocs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"storybook": "pnpm run -C site/ storybook"
},
"devDependencies": {
"@types/url-parse": "^1.4.11",
"prettier": "3.3.3"
},
"dependencies": {
"url-parse": "^1.5.10"
}
}
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion site/src/utils/apps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as TypesGen from "api/typesGenerated";
import URLParse from "url-parse";

export const createAppLinkHref = (
protocol: string,
Expand Down Expand Up @@ -29,7 +30,12 @@ export const createAppLinkHref = (
}

if (appsHost && app.subdomain && app.subdomain_name) {
href = `${protocol}//${appsHost}/`.replace("*", app.subdomain_name);
const url = new URLParse("");
url.set("protocol", protocol);
url.set("hostname", appsHost.replace("*", app.subdomain_name));
url.set("pathname", "/");

href = url.toString();
}
return href;
};
7 changes: 6 additions & 1 deletion site/src/utils/portForward.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { WorkspaceAgentPortShareProtocol } from "api/typesGenerated";
import URLParse from "url-parse";

export const portForwardURL = (
host: string,
Expand All @@ -12,7 +13,11 @@ export const portForwardURL = (
const suffix = protocol === "https" ? "s" : "";

const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`;
return `${location.protocol}//${host}`.replace("*", subdomain);
const url = new URLParse("");
url.set("protocol", location.protocol);
url.set("hostname", host.replace("*", subdomain));

return url.toString();
};

// openMaybePortForwardedURL tries to open the provided URI through the
Expand Down
Loading