Merge pull request #6914 from Kelimion/fix-xml

Fix whitespace normalize
This commit is contained in:
gingerBill
2026-06-30 12:32:41 +01:00
committed by GitHub
2 changed files with 26 additions and 1 deletions

View File

@@ -146,6 +146,7 @@ decode_xml :: proc(input: string, options := XML_Decode_Options{}, allocator :=
for i in 0..<count {
write_rune(&builder, decoded[i])
}
prev = decoded[count - 1]
continue
}
}

View File

@@ -1,5 +1,6 @@
package test_core_xml
import "core:encoding/entity"
import "core:encoding/xml"
import "core:testing"
import "core:strings"
@@ -217,6 +218,29 @@ run_test :: proc(t: ^testing.T, test: TEST, loc := #caller_location) {
}
}
@(test)
test_normalize_whitespace :: proc(t: ^testing.T) {
s := "A &amp; B"
normalized_entity_decode, _ := entity.decode_xml(s, {.Normalize_Whitespace})
defer delete(normalized_entity_decode)
testing.expect_value(t, normalized_entity_decode, "A & B")
s = `<hellope attr="A &amp; B">A &amp; B</hellope>`
opts := xml.Options{
flags = {.Ignore_Unsupported, .Decode_SGML_Entities},
}
doc, err := xml.parse_bytes(transmute([]byte)s, opts)
defer xml.destroy(doc)
assert(err == .None)
testing.expect_value(t, doc.elements[0].value[0], "A & B")
attr := doc.elements[0].attribs
testing.expect_value(t, attr[0].val, "A & B")
}
@(private)
doc_to_string :: proc(doc: ^xml.Document) -> (result: string) {
/*
@@ -298,4 +322,4 @@ doc_to_string :: proc(doc: ^xml.Document) -> (result: string) {
print(strings.to_writer(&buf), doc)
return strings.clone(strings.to_string(buf))
}
}