diff --git a/src/app/search/components/codePreviewPanel/index.tsx b/src/app/search/components/codePreviewPanel/index.tsx index 3cc88cc9..6921663f 100644 --- a/src/app/search/components/codePreviewPanel/index.tsx +++ b/src/app/search/components/codePreviewPanel/index.tsx @@ -1,7 +1,7 @@ 'use client'; import { fetchFileSource } from "@/app/api/(client)/client"; -import { getCodeHostFilePreviewLink } from "@/lib/utils"; +import { getCodeHostFilePreviewLink, base64Decode } from "@/lib/utils"; import { useQuery } from "@tanstack/react-query"; import { CodePreview, CodePreviewFile } from "./codePreview"; import { SearchResultFile } from "@/lib/types"; @@ -32,7 +32,7 @@ export const CodePreviewPanel = ({ // @todo : refector this to use the templates provided by zoekt. const link = getCodeHostFilePreviewLink(fileMatch.Repository, fileMatch.FileName) - const decodedSource = atob(source); + const decodedSource = base64Decode(source); // Filter out filename matches const filteredMatches = fileMatch.ChunkMatches.filter((match) => { diff --git a/src/app/search/components/searchResultsPanel/fileMatch.tsx b/src/app/search/components/searchResultsPanel/fileMatch.tsx index da077878..635fb5b9 100644 --- a/src/app/search/components/searchResultsPanel/fileMatch.tsx +++ b/src/app/search/components/searchResultsPanel/fileMatch.tsx @@ -3,6 +3,7 @@ import { useMemo } from "react"; import { CodePreview } from "./codePreview"; import { SearchResultFile, SearchResultFileMatch } from "@/lib/types"; +import { base64Decode } from "@/lib/utils"; interface FileMatchProps { @@ -17,7 +18,7 @@ export const FileMatch = ({ onOpen, }: FileMatchProps) => { const content = useMemo(() => { - return atob(match.Content); + return base64Decode(match.Content); }, [match.Content]); // If it's just the title, don't show a code preview diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 3eecc21c..15ed59fd 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -95,4 +95,10 @@ export const getEnvBoolean = (env: string | undefined, defaultValue: boolean) => return defaultValue; } return env === 'true' || env === '1'; -} \ No newline at end of file +} + +// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem +export const base64Decode = (base64: string): string => { + const binString = atob(base64); + return Buffer.from(Uint8Array.from(binString, (m) => m.codePointAt(0)!).buffer).toString(); +}