Skip to content

Commit ffc20fd

Browse files
author
ntwigg
committed
Fix serializeOnlyFacets to handle empty, needed for pure additions.
1 parent 0c45d92 commit ffc20fd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

jvm/selfie-lib/src/commonMain/kotlin/com/diffplug/selfie/SelfieImplementations.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ internal fun serializeOnlyFacets(snapshot: Snapshot, keys: Collection<String>):
226226
// this codepath is triggered by the `key.isEmpty()` line above
227227
writer.subSequence(EMPTY_KEY_AND_FACET.length, writer.length - 1).toString()
228228
} else {
229-
writer.setLength(writer.length - 1)
229+
// Check if the writer is empty to avoid StringIndexOutOfBoundsException
230+
if (writer.length > 0) {
231+
writer.setLength(writer.length - 1)
232+
}
230233
writer.toString()
231234
}
232235
}
@@ -249,7 +252,7 @@ private fun <T : Any> toBeDidntMatch(expected: T?, actual: T, format: LiteralFor
249252
}
250253
}
251254
}
252-
internal fun assertEqual(expected: Snapshot?, actual: Snapshot, storage: SnapshotSystem) {
255+
private fun assertEqual(expected: Snapshot?, actual: Snapshot, storage: SnapshotSystem) {
253256
when (expected) {
254257
null -> throw storage.fs.assertFailed(storage.mode.msgSnapshotNotFound())
255258
actual -> return

0 commit comments

Comments
 (0)