[njs] XML: fixed exception handling.
Dmitry Volyntsev
xeioex at nginx.com
Wed Oct 4 22:23:52 UTC 2023
details: https://hg.nginx.org/njs/rev/632002c161b1
branches:
changeset: 2216:632002c161b1
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Oct 04 15:00:02 2023 -0700
description:
XML: fixed exception handling.
This closes #675 issue on Github.
diffstat:
external/njs_xml_module.c | 2 +-
src/test/njs_unit_test.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletions(-)
diffs (26 lines):
diff -r c0aad58cfadb -r 632002c161b1 external/njs_xml_module.c
--- a/external/njs_xml_module.c Wed Oct 04 13:35:38 2023 -0700
+++ b/external/njs_xml_module.c Wed Oct 04 15:00:02 2023 -0700
@@ -2000,7 +2000,7 @@ njs_xml_error(njs_vm_t *vm, njs_xml_doc_
err->int2);
}
- njs_vm_error(vm, "%s", p - errstr, errstr);
+ njs_vm_error(vm, "%*s", p - errstr, errstr);
}
diff -r c0aad58cfadb -r 632002c161b1 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Oct 04 13:35:38 2023 -0700
+++ b/src/test/njs_unit_test.c Wed Oct 04 15:00:02 2023 -0700
@@ -22035,6 +22035,10 @@ static njs_unit_test_t njs_xml_test[] =
njs_str("FOO,BAR,0,2") },
{ njs_str("const xml = require('xml');"
+ "let doc = xml.parse(`GARBAGE`)"),
+ njs_str("Error: failed to parse XML (libxml2: \"Start tag expected, '<' not found\" at 1:1)") },
+
+ { njs_str("const xml = require('xml');"
"let doc = xml.parse(`<r><a></a>TEXT</r>`);"
"doc.r.$text"),
njs_str("TEXT") },
More information about the nginx-devel
mailing list