Don't use assert in parseDossierLegislatif because it can be used by browsers

This commit is contained in:
Emmanuel 2024-05-22 19:05:10 +02:00
parent ea68e23e4a
commit c2ad2c4926

View file

@ -1,5 +1,4 @@
import { auditChain, auditRequire, strictAudit } from "@auditors/core" import { auditChain, auditRequire, strictAudit } from "@auditors/core"
import assert from "assert"
import { XMLParser } from "fast-xml-parser" import { XMLParser } from "fast-xml-parser"
import he from "he" import he from "he"
@ -33,8 +32,14 @@ export function parseDossierLegislatif(
switch (key) { switch (key) {
case "?xml": { case "?xml": {
const xmlHeader = element as XmlHeader const xmlHeader = element as XmlHeader
assert.strictEqual(xmlHeader["@encoding"], "UTF-8", filePath) if (
assert.strictEqual(xmlHeader["@version"], "1.0", filePath) xmlHeader["@encoding"] !== "UTF-8" ||
xmlHeader["@version"] !== "1.0"
) {
throw new Error(
`Unexpected XML header for ${filePath}: ${JSON.stringify(xmlHeader)}`,
)
}
break break
} }
case "DOSSIER_LEGISLATIF": { case "DOSSIER_LEGISLATIF": {
@ -42,15 +47,16 @@ export function parseDossierLegislatif(
auditDossierLegislatif, auditDossierLegislatif,
auditRequire, auditRequire,
)(strictAudit, element) as [DossierLegislatif, unknown] )(strictAudit, element) as [DossierLegislatif, unknown]
assert.strictEqual( if (error !== null) {
error, throw new Error(
null, `Unexpected format for DOSSIER_LEGISLATIF:\n${JSON.stringify(
`Unexpected format for DOSSIER_LEGISLATIF:\n${JSON.stringify( dossierLegislatif,
dossierLegislatif, null,
null, 2,
2, )}\nError:\n${JSON.stringify(error, null, 2)}`,
)}\nError:\n${JSON.stringify(error, null, 2)}`, )
) }
return dossierLegislatif return dossierLegislatif
} }
default: { default: {