fix(pdf): report:compare --diff follows the privacy default, generic reason on a malformed attachment, Unicode control and format characters escaped, regular files only
This commit is contained in:
1 parent
b1b3e4927e
commit
388e209ea9
4 files changed
+48
-20
No files matched your search
@@ -8,9 +8,10 @@
|
||||
* A v2 archive PDF is shown legacy id → canonical id, line by line; a v3 PDF
|
||||
* is checked against the sheet. Items the sheet cannot place are marked
|
||||
* `!! UNRESOLVED` with the reason. `--diff` compares the v3 content of two
|
||||
* PDFs (an archive and its re-export after import, typically) and prints a
|
||||
* differing text line in clear. By default only identifiers, catalog labels,
|
||||
* counts and placeholders are printed; names and free texts need `--full`.
|
||||
* PDFs (an archive and its re-export after import, typically). By default
|
||||
* only identifiers, catalog labels, counts and placeholders are printed and
|
||||
* compared (a text shows as `conclusion (present)`); names and free texts,
|
||||
* printed and compared, need `--full`.
|
||||
* Untrusted strings are printed with control characters escaped. It writes
|
||||
* no output file.
|
||||
*/
|
||||
@@ -79,7 +80,9 @@ async function compareFile(
|
||||
sheet: SheetIndex,
|
||||
args: CliArgs,
|
||||
): Promise<Comparison> {
|
||||
if (statSync(path).size > MAX_PDF_BYTES) throw new Error('file too large')
|
||||
const st = statSync(path)
|
||||
if (!st.isFile()) throw new Error('not a regular file')
|
||||
if (st.size > MAX_PDF_BYTES) throw new Error('file too large')
|
||||
const bytes = new Uint8Array(readFileSync(path))
|
||||
const pdf = await PDFDocument.load(bytes, { ignoreEncryption: true })
|
||||
const raw = await readAttachedDocument(pdf)
|
||||
@@ -100,6 +103,8 @@ function failureReason(err: unknown): string {
|
||||
const code = (err as NodeJS.ErrnoException | undefined)?.code
|
||||
if (code === 'ENOENT') return 'file not found'
|
||||
if (code === 'EACCES') return 'file not readable'
|
||||
// JSON.parse messages echo a fragment of the attachment.
|
||||
if (err instanceof SyntaxError) return 'attachment is not valid JSON'
|
||||
return err instanceof Error ? err.message : String(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user