Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffb0ebb

Browse files
authored
fix: use url-parse for url construction (#15670)
This fixes some CodeQL-flagged issues. They're not real issues but the refactor is small and it'll keep the analysis tools quiet.
1 parent 40f12ae commit ffb0ebb

File tree

5 files changed

+103
-11
lines changed

5 files changed

+103
-11
lines changed

offlinedocs/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
"react-icons": "4.12.0",
2727
"react-markdown": "9.0.1",
2828
"rehype-raw": "7.0.0",
29-
"remark-gfm": "4.0.0"
29+
"remark-gfm": "4.0.0",
30+
"sanitize-html": "2.13.1"
3031
},
3132
"devDependencies": {
3233
"@types/lodash": "4.17.13",
3334
"@types/node": "20.17.6",
3435
"@types/react": "18.3.12",
3536
"@types/react-dom": "18.3.1",
37+
"@types/sanitize-html": "2.13.0",
3638
"eslint": "8.57.1",
3739
"eslint-config-next": "14.2.16",
3840
"prettier": "3.3.3",

offlinedocs/pages/[[...slug]].tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { MdMenu } from "react-icons/md";
3838
import ReactMarkdown from "react-markdown";
3939
import rehypeRaw from "rehype-raw";
4040
import remarkGfm from "remark-gfm";
41+
import sanitizeHtml from "sanitize-html";
4142

4243
type FilePath = string;
4344
type UrlPath = string;
@@ -194,10 +195,6 @@ const getNavigation = (manifest: Manifest): Nav => {
194195
return navigation;
195196
};
196197

197-
const removeHtmlComments = (string: string) => {
198-
return string.replace(/<!--[\s\S]*?-->/g, "");
199-
};
200-
201198
export const getStaticPaths: GetStaticPaths = () => {
202199
const manifest = getManifest();
203200
const routes = mapRoutes(manifest);
@@ -221,7 +218,7 @@ export const getStaticProps: GetStaticProps = (context) => {
221218
const route = routes[urlPath];
222219
const { body } = fm(readContentFile(route.path));
223220
// Serialize MDX to support custom components
224-
const content = removeHtmlComments(body);
221+
const content = sanitizeHtml(body);
225222
const navigation = getNavigation(manifest);
226223
const version = manifest.versions[0];
227224

offlinedocs/pnpm-lock.yaml

+86-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/utils/apps.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export const createAppLinkHref = (
2929
}
3030

3131
if (appsHost && app.subdomain && app.subdomain_name) {
32-
href = `${protocol}//${appsHost}/`.replace("*", app.subdomain_name);
32+
const baseUrl = `${protocol}//${appsHost}`;
33+
const url = new URL(baseUrl);
34+
url.hostname = appsHost.replace("*", app.subdomain_name);
35+
url.pathname = "/";
36+
37+
href = url.toString();
3338
}
3439
return href;
3540
};

site/src/utils/portForward.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export const portForwardURL = (
1212
const suffix = protocol === "https" ? "s" : "";
1313

1414
const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`;
15-
return `${location.protocol}//${host}`.replace("*", subdomain);
15+
16+
const baseUrl = `${location.protocol}//${host}`;
17+
const url = new URL(baseUrl);
18+
url.hostname = host.replace("*", subdomain);
19+
20+
return url.toString();
1621
};
1722

1823
// openMaybePortForwardedURL tries to open the provided URI through the

0 commit comments

Comments
 (0)