Skip to content

Commit b7ddc7d

Browse files
authored
encoding.xml: fix handling of CRLF (windows EOLs) (fix #25345) (#25376)
1 parent e9cd499 commit b7ddc7d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎vlib/encoding/xml/newline_test.v‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import encoding.xml
2+
3+
fn test_newline() {
4+
doc := xml.XMLDocument.from_string('<?xml version="1.0" encoding="UTF-8"?>
5+
<feed\r\nattr="value">
6+
<title>Test</title>
7+
</feed>
8+
\r\n<\r\ntest\r\n>\r
9+
<\r\n/\ntest\r>
10+
')!
11+
_ = doc
12+
}

‎vlib/encoding/xml/parser.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn parse_entity(contents string) !(DTDEntity, string) {
195195
fn parse_element(contents string) !(DTDElement, string) {
196196
// We find the nearest '>' to the start of the ELEMENT
197197
element_end := contents.index('>') or { return error('Element declaration not closed.') }
198-
element_contents := contents[element_len..element_end].trim_left(' \t\n')
198+
element_contents := contents[element_len..element_end].trim_left(' \t\r\n')
199199

200200
mut name_span := TextSpan{}
201201

@@ -559,7 +559,7 @@ pub fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode {
559559

560560
tag_contents := contents.str().trim_space()
561561

562-
parts := tag_contents.split_any(' \t\n')
562+
parts := tag_contents.split_any(' \t\r\n')
563563
name := parts[0].trim_right('/')
564564

565565
// Check if it is a self-closing tag

0 commit comments

Comments
 (0)