fix(ancpi): decode HTML entities before parsing document info from OrderDetails
This commit is contained in:
@@ -541,6 +541,15 @@ export class EpayClient {
|
||||
|
||||
const documents: EpaySolutionDoc[] = [];
|
||||
|
||||
// Decode HTML entities — ePay embeds JSON with " encoding
|
||||
const decoded = html
|
||||
.replace(/"/g, '"')
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/ț/g, "ț")
|
||||
.replace(/ș/g, "ș");
|
||||
|
||||
// Try multiple patterns to find document info in the Angular HTML
|
||||
// Pattern 1: JSON-like in Angular scope
|
||||
const docPattern1 =
|
||||
@@ -554,11 +563,8 @@ export class EpayClient {
|
||||
const docPattern2b =
|
||||
/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;
|
||||
while ((docMatch = docPattern1.exec(html)) !== null) {
|
||||
while ((docMatch = docPattern1.exec(decoded)) !== null) {
|
||||
documents.push({
|
||||
idDocument: parseInt(docMatch[1] ?? "0", 10),
|
||||
idTipDocument: null,
|
||||
@@ -580,10 +586,10 @@ export class EpayClient {
|
||||
// Combine results from both patterns
|
||||
const allDocIds = new Set<number>();
|
||||
|
||||
while ((docMatch = docPattern2.exec(html)) !== null) {
|
||||
while ((docMatch = docPattern2.exec(decoded)) !== null) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -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 (documents.length === 0 && solutiiMatch) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user