From 1482a2f28dfc07c8c588be31459622c47c4585c3 Mon Sep 17 00:00:00 2001 From: Subhomoy Haldar Date: Fri, 17 Nov 2023 08:51:46 +0000 Subject: [PATCH] encoding.xml: fix parsing for self closing empty tags (#19907) --- vlib/encoding/xml/parser.v | 2 +- vlib/encoding/xml/parser_test.v | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vlib/encoding/xml/parser.v b/vlib/encoding/xml/parser.v index 86dbc6594c..9a52d1d31d 100644 --- a/vlib/encoding/xml/parser.v +++ b/vlib/encoding/xml/parser.v @@ -562,7 +562,7 @@ pub fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode { tag_contents := contents.str().trim_space() parts := tag_contents.split_any(' \t\n') - name := parts[0] + name := parts[0].trim_right('/') // Check if it is a self-closing tag if tag_contents.ends_with('/') { diff --git a/vlib/encoding/xml/parser_test.v b/vlib/encoding/xml/parser_test.v index 3de74829b2..368534d975 100644 --- a/vlib/encoding/xml/parser_test.v +++ b/vlib/encoding/xml/parser_test.v @@ -7,6 +7,7 @@ const ( Sample Text + @@ -34,6 +35,10 @@ const ( 'Sample Text', ] }, + XMLNode{ + name: 'empty' + attributes: {} + }, XMLNode{ name: 'c' attributes: {