Skip to content

Commit 002683e

Browse files
committed
Additional fix for bug #44, as well as test code.
1 parent 890b951 commit 002683e

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

core/src/commonMain/kotlin/nl/adaptivity/xmlutil/XmlReader.kt

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ fun XmlReader.readSimpleElement(): String {
348348
EventType.PROCESSING_INSTRUCTION -> {
349349
}
350350
EventType.TEXT,
351+
EventType.ENTITY_REF,
351352
EventType.CDSECT -> append(t.text)
352353
else -> throw XmlException(
353354
"Expected text content or end tag, found: ${t.eventType}"

serialization/src/commonTest/kotlin/nl/adaptivity/xml/serialization/TestCommon.kt

+19
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ class TestCommon {
131131
assertEquals(contentText, serialized)
132132
}
133133

134+
135+
@Test
136+
fun deserializeXmlWithEntity() {
137+
val xml = XML {
138+
repairNamespaces = true
139+
policy = DefaultXmlSerializationPolicy(pedantic = false, autoPolymorphic = false)
140+
}
141+
142+
val expected = StringWithMarkup("Chloroacetic acid, >=99%")
143+
144+
val actual = xml.decodeFromString<StringWithMarkup>(
145+
"<StringWithMarkup xmlns=\"http://pubchem.ncbi.nlm.nih.gov/pug_view\">\n" +
146+
" <String>Chloroacetic acid, &gt;=99%</String>\n" +
147+
"</StringWithMarkup>"
148+
)
149+
assertEquals(expected, actual)
150+
}
151+
152+
134153
@Serializable
135154
data class IntList(val values: List<Int>)
136155

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
@XmlSerialName("StringWithMarkup", "http://pubchem.ncbi.nlm.nih.gov/pug_view", "")
3+
@Serializable
4+
data class StringWithMarkup(
5+
@XmlElement(true) @SerialName("String") val string: String = "",
6+
val markup: List<String> = emptyList()
7+
)

0 commit comments

Comments
 (0)