fix(ancpi): decode HTML entities before parsing document info from OrderDetails

This commit is contained in:
AI Assistant
2026-03-23 03:38:36 +02:00
parent e63ec4c6c8
commit 6185defa8b
@@ -541,6 +541,15 @@ export class EpayClient {
const documents: EpaySolutionDoc[] = []; const documents: EpaySolutionDoc[] = [];
// Decode HTML entities — ePay embeds JSON with " encoding
const decoded = html
.replace(/"/g, '"')
.replace(/&/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&#x21B;/g, "ț")
.replace(/&#x219;/g, "ș");
// Try multiple patterns to find document info in the Angular HTML // Try multiple patterns to find document info in the Angular HTML
// Pattern 1: JSON-like in Angular scope // Pattern 1: JSON-like in Angular scope
const docPattern1 = const docPattern1 =
@@ -554,11 +563,8 @@ export class EpayClient {
const docPattern2b = const docPattern2b =
/downloadFile\s*\(\s*\$event\s*,\s*4\s*,\s*(\d+)/g; /downloadFile\s*\(\s*\$event\s*,\s*4\s*,\s*(\d+)/g;
// Pattern 3: Look for solutii JSON array
const solutiiMatch = html.match(/solutii['"]\s*:\s*(\[[\s\S]*?\])/);
let docMatch; let docMatch;
while ((docMatch = docPattern1.exec(html)) !== null) { while ((docMatch = docPattern1.exec(decoded)) !== null) {
documents.push({ documents.push({
idDocument: parseInt(docMatch[1] ?? "0", 10), idDocument: parseInt(docMatch[1] ?? "0", 10),
idTipDocument: null, idTipDocument: null,
@@ -580,10 +586,10 @@ export class EpayClient {
// Combine results from both patterns // Combine results from both patterns
const allDocIds = new Set<number>(); const allDocIds = new Set<number>();
while ((docMatch = docPattern2.exec(html)) !== null) { while ((docMatch = docPattern2.exec(decoded)) !== null) {
allDocIds.add(parseInt(docMatch[1] ?? "0", 10)); allDocIds.add(parseInt(docMatch[1] ?? "0", 10));
} }
while ((docMatch = docPattern2b.exec(html)) !== null) { while ((docMatch = docPattern2b.exec(decoded)) !== null) {
allDocIds.add(parseInt(docMatch[1] ?? "0", 10)); allDocIds.add(parseInt(docMatch[1] ?? "0", 10));
} }
@@ -607,6 +613,9 @@ export class EpayClient {
} }
} }
// Pattern 3: Look for solutii JSON array (in decoded HTML)
const solutiiMatch = decoded.match(/solutii['"]\s*:\s*(\[[\s\S]*?\])/);
// If pattern 3 matched, try to parse JSON // If pattern 3 matched, try to parse JSON
if (documents.length === 0 && solutiiMatch) { if (documents.length === 0 && solutiiMatch) {
try { try {