mirror of
https://github.com/vlang/v.git
synced 2025-09-09 15:27:05 -04:00
encoding.xml: fix parsing of single letter tag names (#19815)
This commit is contained in:
parent
10160c0cae
commit
cd2e36a44d
@ -534,9 +534,12 @@ fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode {
|
|||||||
if ch == `/` {
|
if ch == `/` {
|
||||||
return error('XML node cannot start with "</".')
|
return error('XML node cannot start with "</".')
|
||||||
}
|
}
|
||||||
contents.write_u8(ch)
|
|
||||||
|
|
||||||
for {
|
if ch != `>` {
|
||||||
|
contents.write_u8(ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
for ch != `>` {
|
||||||
ch = next_char(mut reader, mut local_buf)!
|
ch = next_char(mut reader, mut local_buf)!
|
||||||
if ch == `>` {
|
if ch == `>` {
|
||||||
break
|
break
|
||||||
@ -547,7 +550,7 @@ fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode {
|
|||||||
tag_contents := contents.str().trim_space()
|
tag_contents := contents.str().trim_space()
|
||||||
|
|
||||||
parts := tag_contents.split_any(' \t\n')
|
parts := tag_contents.split_any(' \t\n')
|
||||||
name := first_char.ascii_str() + parts[0]
|
name := if parts.len > 0 { first_char.ascii_str() + parts[0] } else { first_char.ascii_str() }
|
||||||
|
|
||||||
// Check if it is a self-closing tag
|
// Check if it is a self-closing tag
|
||||||
if tag_contents.ends_with('/') {
|
if tag_contents.ends_with('/') {
|
||||||
|
18
vlib/encoding/xml/test/local/18_single_letter_tag/shared.xml
Normal file
18
vlib/encoding/xml/test/local/18_single_letter_tag/shared.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<sst count="5" uniqueCount="5">
|
||||||
|
<si>
|
||||||
|
<t>Item 1</t>
|
||||||
|
</si>
|
||||||
|
<si>
|
||||||
|
<t>Item 2</t>
|
||||||
|
</si>
|
||||||
|
<si>
|
||||||
|
<t>Item 3</t>
|
||||||
|
</si>
|
||||||
|
<si>
|
||||||
|
<t>Item 4</t>
|
||||||
|
</si>
|
||||||
|
<si>
|
||||||
|
<t>Item 5</t>
|
||||||
|
</si>
|
||||||
|
</sst>
|
@ -0,0 +1,68 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
import os
|
||||||
|
import encoding.xml
|
||||||
|
|
||||||
|
fn test_valid_parsing() {
|
||||||
|
path := os.join_path(os.dir(@FILE), 'shared.xml')
|
||||||
|
|
||||||
|
expected := xml.XMLDocument{
|
||||||
|
root: xml.XMLNode{
|
||||||
|
name: 'sst'
|
||||||
|
attributes: {
|
||||||
|
'count': '5'
|
||||||
|
'uniqueCount': '5'
|
||||||
|
}
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 'si'
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 't'
|
||||||
|
children: ['Item 1']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 'si'
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 't'
|
||||||
|
children: ['Item 2']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 'si'
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 't'
|
||||||
|
children: ['Item 3']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 'si'
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 't'
|
||||||
|
children: ['Item 4']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 'si'
|
||||||
|
children: [
|
||||||
|
xml.XMLNode{
|
||||||
|
name: 't'
|
||||||
|
children: ['Item 5']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actual := xml.XMLDocument.from_file(path)!
|
||||||
|
|
||||||
|
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user