From b7ddc7da4853de0167532f1f4066827e86c6a42d Mon Sep 17 00:00:00 2001 From: CreeperFace <165158232+dy-tea@users.noreply.github.com> Date: Mon, 22 Sep 2025 21:14:52 +0200 Subject: [PATCH] encoding.xml: fix handling of CRLF (windows EOLs) (fix #25345) (#25376) --- vlib/encoding/xml/newline_test.v | 12 ++++++++++++ vlib/encoding/xml/parser.v | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 vlib/encoding/xml/newline_test.v diff --git a/vlib/encoding/xml/newline_test.v b/vlib/encoding/xml/newline_test.v new file mode 100644 index 000000000..f4458d2a1 --- /dev/null +++ b/vlib/encoding/xml/newline_test.v @@ -0,0 +1,12 @@ +import encoding.xml + +fn test_newline() { + doc := xml.XMLDocument.from_string(' + + Test + +\r\n<\r\ntest\r\n>\r +<\r\n/\ntest\r> +')! + _ = doc +} diff --git a/vlib/encoding/xml/parser.v b/vlib/encoding/xml/parser.v index 1bfa19c44..15933ac29 100644 --- a/vlib/encoding/xml/parser.v +++ b/vlib/encoding/xml/parser.v @@ -195,7 +195,7 @@ fn parse_entity(contents string) !(DTDEntity, string) { fn parse_element(contents string) !(DTDElement, string) { // We find the nearest '>' to the start of the ELEMENT element_end := contents.index('>') or { return error('Element declaration not closed.') } - element_contents := contents[element_len..element_end].trim_left(' \t\n') + element_contents := contents[element_len..element_end].trim_left(' \t\r\n') mut name_span := TextSpan{} @@ -559,7 +559,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') + parts := tag_contents.split_any(' \t\r\n') name := parts[0].trim_right('/') // Check if it is a self-closing tag -- 2.39.5