Skip to content

Commit

Permalink
Fix native/javascript siblingsToFragment so that it doesn't end up in…
Browse files Browse the repository at this point in the history
… an infinite

loop on end of content.
  • Loading branch information
pdvrieze committed Sep 11, 2024
1 parent 479f267 commit 43ba1bf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Changes:
This aids #225.

Fixes:
- Fix siblingsToFragment for native/js so that it terminates on end of
stream, even if this doesn't include DocumentEnd event.
- Make `@XmlValue` work with regular types (to support generic parsing
of element content of variable type, some including mixed/text content)
- Better support `XmlSerialName` where value (localname) is defaulted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public actual fun XmlReader.siblingsToFragment(): CompactFragment {


var type: EventType? = eventType
while (type !== EventType.END_DOCUMENT && type !== EventType.END_ELEMENT && depth >= initialDepth) {
while (type !== EventType.END_DOCUMENT && (type !== EventType.END_ELEMENT || depth > initialDepth)) {
when (type) {
EventType.START_ELEMENT ->
KtXmlWriter(appendable, isRepairNamespaces = false, xmlDeclMode = XmlDeclMode.None).use { out ->
Expand All @@ -66,7 +66,7 @@ public actual fun XmlReader.siblingsToFragment(): CompactFragment {
else -> {
} // ignore
}
type = if (hasNext()) next() else null
type = if (hasNext()) next() else break
}

if (missingNamespaces[""] == "") missingNamespaces.remove("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public actual fun XmlReader.siblingsToFragment(): CompactFragment {
// If we are at a start tag, the depth will already have been increased. So in that case, reduce one.
val initialDepth = depth - if (eventType === EventType.START_ELEMENT) 1 else 0
var type: EventType? = eventType
while (type !== EventType.END_DOCUMENT && type !== EventType.END_ELEMENT && depth >= initialDepth) {
while (type !== EventType.END_DOCUMENT && (type !== EventType.END_ELEMENT || depth > initialDepth)) {
when (type) {
EventType.START_ELEMENT -> {
@Suppress("DEPRECATION")
Expand All @@ -91,7 +91,7 @@ public actual fun XmlReader.siblingsToFragment(): CompactFragment {

else -> Unit // These elements are ignored/not part of a fragment
}
type = if (hasNext()) next() else null
type = if (hasNext()) next() else break
}

if (missingNamespaces[""] == "") missingNamespaces.remove("")
Expand Down

0 comments on commit 43ba1bf

Please sign in to comment.