Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

fix(report-pdf): drop dead CJK font ternary, document the Hangul gap, add tests

Sergey Kozyrenko47c1ea108bc2
diff --git a/frontend/src/lib/report/report-pdf.test.ts b/frontend/src/lib/report/report-pdf.test.ts
new file mode 100644
index 00000000..b53e8d34
--- /dev/null
+++ b/frontend/src/lib/report/report-pdf.test.ts
@@ -0,0 +1,62 @@
+import type { ReactElement } from 'react';
+
+import { describe, expect, it } from 'vitest';
+
+import { renderTextWithCJK, splitByCJK } from './report-pdf';
+
+type CJKElement = ReactElement<{ style: Record<string, string | undefined> }>;
+
+describe('splitByCJK', () => {
+ it('returns a single non-CJK segment for plain Latin text', () => {
+ expect(splitByCJK('hello world')).toEqual([{ isCJK: false, text: 'hello world' }]);
+ });
+
+ it('returns a single CJK segment for Chinese text', () => {
+ expect(splitByCJK('中文')).toEqual([{ isCJK: true, text: '中文' }]);
+ });
+
+ it('splits mixed Latin and CJK into alternating segments', () => {
+ expect(splitByCJK('Hello 世界 ok')).toEqual([
+ { isCJK: false, text: 'Hello ' },
+ { isCJK: true, text: '世界' },
+ { isCJK: false, text: ' ok' },
+ ]);
+ });
+
+ it('detects Japanese kana as CJK', () => {
+ expect(splitByCJK('あいうカ')).toEqual([{ isCJK: true, text: 'あいうカ' }]);
+ });
+
+ it('detects Korean hangul as CJK even though NotoSansSC cannot render it', () => {
+ expect(splitByCJK('한국어')).toEqual([{ isCJK: true, text: '한국어' }]);
+ });
+
+ it('treats CJK punctuation as CJK', () => {
+ expect(splitByCJK('「x」')).toEqual([
+ { isCJK: true, text: '「' },
+ { isCJK: false, text: 'x' },
+ { isCJK: true, text: '」' },
+ ]);
+ });
+
+ it('falls back to a single empty non-CJK segment for empty input', () => {
+ expect(splitByCJK('')).toEqual([{ isCJK: false, text: '' }]);
+ });
+});
+
+describe('renderTextWithCJK', () => {
+ it('returns the raw string when there is no CJK to split', () => {
+ expect(renderTextWithCJK('plain text', 'Base', 'Bold', 'k')).toBe('plain text');
+ });
+
+ it('renders CJK on NotoSansSC and Latin on the base family', () => {
+ const out = renderTextWithCJK('A中', 'Base', 'Bold', 'k') as CJKElement[];
+ expect(out.map((element) => element.props.style.fontFamily)).toEqual(['Base', 'NotoSansSC']);
+ });
+
+ it('bolds only the Latin segment and keeps CJK on NotoSansSC when bold', () => {
+ const out = renderTextWithCJK('A中', 'Base', 'Bold', 'k', true) as CJKElement[];
+ expect(out[0]?.props.style).toMatchObject({ fontFamily: 'Bold', fontWeight: 'bold' });
+ expect(out[1]?.props.style).toEqual({ fontFamily: 'NotoSansSC' });
+ });
+});
diff --git a/frontend/src/lib/report/report-pdf.tsx b/frontend/src/lib/report/report-pdf.tsx
index edac39ea..54b1df55 100644
--- a/frontend/src/lib/report/report-pdf.tsx
+++ b/frontend/src/lib/report/report-pdf.tsx
@@ -44,6 +44,9 @@ const registerCJKFonts = (): void => {
return;
}
+ // NotoSansSC covers Han, kana and Bopomofo but NOT Hangul, so Korean text
+ // still renders as missing-glyph boxes. Register NotoSansKR and route Hangul
+ // segments to it to support Korean.
Font.register({
family: 'NotoSansSC',
fonts: [
@@ -72,7 +75,7 @@ interface TextSegment {
* Splits a string into alternating non-CJK and CJK segments so each segment
* can be rendered with the appropriate font family.
*/
-const splitByCJK = (text: string): TextSegment[] => {
+export const splitByCJK = (text: string): TextSegment[] => {
const segments: TextSegment[] = [];
let lastIndex = 0;
@@ -417,7 +420,7 @@ const parseMarkdownTokens = (markdown: string): ParsedContent[] => {
* Noto Sans for Latin/Cyrillic, Noto Sans SC for CJK. CJK fonts have no true italic
* variant, so italic is dropped for those segments.
*/
-const renderTextWithCJK = (
+export const renderTextWithCJK = (
text: string,
baseFamily: string,
boldFamily: string,
@@ -432,7 +435,7 @@ const renderTextWithCJK = (
}
return segments.map((seg, idx) => {
- const family = seg.isCJK ? (bold ? 'NotoSansSC' : 'NotoSansSC') : bold ? boldFamily : baseFamily;
+ const family = seg.isCJK ? 'NotoSansSC' : bold ? boldFamily : baseFamily;
const style: Record<string, string> = { fontFamily: family };
if (bold && !seg.isCJK) {