From c2fd12b5bd642b823c8f6c22b49eb7dfdcc643f2 Mon Sep 17 00:00:00 2001 From: Affan Ziya Date: Fri, 20 Nov 2026 18:40:43 +0530 Subject: [PATCH] printer xml BUGFIX encode namespace values --- src/printer_xml.c | 4 +++- tests/utests/data/test_printer_xml.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/printer_xml.c b/src/printer_xml.c index e1afb814a0..1e983f5a7d 100644 --- a/src/printer_xml.c +++ b/src/printer_xml.c @@ -95,7 +95,9 @@ xml_print_ns(struct xmlpr_ctx *pctx, const char *ns, const char *new_prefix, uin } /* suitable namespace not found, must be printed */ - ly_print_(pctx->out, " xmlns%s%s=\"%s\"", new_prefix ? ":" : "", new_prefix ? new_prefix : "", ns); + ly_print_(pctx->out, " xmlns%s%s=\"", new_prefix ? ":" : "", new_prefix ? new_prefix : ""); + lyxml_dump_text(pctx->out, ns, 1); + ly_print_(pctx->out, "\""); /* and added into namespaces */ if (new_prefix) { diff --git a/tests/utests/data/test_printer_xml.c b/tests/utests/data/test_printer_xml.c index 9fa901b25c..a5ca58fc3e 100644 --- a/tests/utests/data/test_printer_xml.c +++ b/tests/utests/data/test_printer_xml.c @@ -114,6 +114,12 @@ test_anydata(void **state) CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_SIBLINGS, data); lyd_free_all(tree); + /* namespace with characters that need encoding */ + data = ""; + CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); + CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_SIBLINGS, data); + lyd_free_all(tree); + data = ""; CHECK_PARSE_LYD(data, 0, LYD_VALIDATE_PRESENT, tree); CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_SIBLINGS, data);