Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/search/components/codePreviewPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/search/components/searchResultsPanel/fileMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,10 @@ export const getEnvBoolean = (env: string | undefined, defaultValue: boolean) =>
return defaultValue;
}
return env === 'true' || env === '1';
}
}

// 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();
}