Improve unsupported PDF character errors
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 30s
Build and Push Docker Images / build-frontend (push) Successful in 1m12s
Build and Push Docker Images / build-website (push) Successful in 18s
Build and Push Docker Images / build-docs (push) Successful in 17s
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 30s
Build and Push Docker Images / build-frontend (push) Successful in 1m12s
Build and Push Docker Images / build-website (push) Successful in 18s
Build and Push Docker Images / build-docs (push) Successful in 17s
This commit is contained in:
27
backend/tests/pdfCharacterError.test.ts
Normal file
27
backend/tests/pdfCharacterError.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import assert from "node:assert/strict"
|
||||
import test from "node:test"
|
||||
import { getUnsupportedPdfCharacterMessage } from "../src/utils/pdfCharacterError"
|
||||
|
||||
test("reports unsupported characters with the document position and character offset", () => {
|
||||
// pdf-lib displays supplementary Unicode characters as a private-use glyph,
|
||||
// while the hexadecimal value still contains the original code point.
|
||||
const error = new Error('WinAnsi cannot encode "" (0x1f600)')
|
||||
const documentData = {
|
||||
rows: [
|
||||
{ pos: "1", text: "Montage" },
|
||||
{ pos: "2.3", descriptionText: "Gerät 😀 montieren" },
|
||||
],
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
getUnsupportedPdfCharacterMessage(error, documentData),
|
||||
"Das Zeichen „😀“ (Unicode U+1F600) wird in PDF-Dokumenten nicht unterstützt. Fundstelle: Position 2.3, Beschreibung, Zeichen 7. Bitte ersetze oder entferne das Zeichen."
|
||||
)
|
||||
})
|
||||
|
||||
test("returns null for unrelated PDF errors", () => {
|
||||
assert.equal(
|
||||
getUnsupportedPdfCharacterMessage(new Error("Background PDF is invalid"), {}),
|
||||
null
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user