Skip to content

Commit 511f77c

Browse files
committed
Additional fix for bug #44, as well as test code.
1 parent 67939b6 commit 511f77c

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
@@ -132,6 +132,25 @@ class TestCommon {
132132
assertEquals(contentText, serialized)
133133
}
134134

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

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)