Merge pull request #6512 from Jazzcort/sanitize-doc-url

Fix: add sanitizing process to strip off the trailing slash of the doc URL
This commit is contained in:
Dallin Romney 2025-07-16 22:53:54 +02:00 • committed by GitHub
commit 33d44cd540
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,15 @@ export interface SiteIndexingResults {
title: string;
}
/**
* Strip off the trailing forward slash from the given URL
* @param url The URL of the document
* @returns A sanitized URL without trailing forward slash
*/
const stripTrailingSlash = (url: string): string => {
return url.replace(/\/+$/, "");
};
export class DocsCache {
static readonly AWS_REGION: string = "us-west-1";
static readonly BUCKET_NAME: string = "continue-preindexed-docs";
@ -33,7 +42,8 @@ export class DocsCache {
url: string,
): string {
const normalizedEmbeddingId = DocsCache.normalizeEmbeddingId(embeddingId);
const normalizedUrl = encodeURIComponent(url.replace(/\//g, "_"));
const sanitizedUrl = stripTrailingSlash(url);
const normalizedUrl = encodeURIComponent(sanitizedUrl.replace(/\//g, "_"));
return normalizedEmbeddingId + "/" + normalizedUrl;
}