Skip to content

Commit 30116cf

Browse files
committed
fix(compare-rendering): scope JSON_END search and resolve REPO_ROOT via fileURLToPath
Two small fixes from PR review: - parseExtractionOutput searched for JSON_END from offset 0, so a document whose paragraph text contained the literal string "JSON_END" could truncate the payload before JSON.parse. Search from past JSON_BEGIN instead. - REPO_ROOT in superdoc.ts was using URL.pathname, which yields /C:/… on Windows and keeps URL-encoded special chars. Use fileURLToPath like we already do in cache.ts / word.ts.
1 parent 370bb88 commit 30116cf

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

devtools/compare-rendering/src/superdoc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
22
import { mkdtemp, readFile, rm } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
5+
import { fileURLToPath } from 'node:url';
56

67
type SuperDocSnapshot = {
78
layoutSnapshot: {
@@ -29,7 +30,7 @@ export type SuperDocExtraction = {
2930
pageCount: number;
3031
};
3132

32-
const REPO_ROOT = new URL('../../../', import.meta.url).pathname;
33+
const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url));
3334

3435
export async function extractSuperDoc(
3536
docxPath: string,

devtools/compare-rendering/src/word.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ async function runPowerShell(script: string, timeoutSeconds: number): Promise<st
6161

6262
function parseExtractionOutput(output: string): WordExtraction {
6363
const begin = output.indexOf('JSON_BEGIN');
64-
const end = output.indexOf('JSON_END');
65-
if (begin === -1 || end === -1) {
66-
throw new Error(`extract-layout.ps1: missing JSON markers\n${output.slice(0, 800)}`);
64+
if (begin === -1) {
65+
throw new Error(`extract-layout.ps1: missing JSON_BEGIN marker\n${output.slice(0, 800)}`);
6766
}
68-
const json = output.slice(begin + 'JSON_BEGIN'.length, end).trim();
67+
const payloadStart = begin + 'JSON_BEGIN'.length;
68+
const end = output.indexOf('JSON_END', payloadStart);
69+
if (end === -1) {
70+
throw new Error(`extract-layout.ps1: missing JSON_END marker\n${output.slice(0, 800)}`);
71+
}
72+
const json = output.slice(payloadStart, end).trim();
6973
return JSON.parse(json) as WordExtraction;
7074
}
7175

0 commit comments

Comments
 (0)