File tree Expand file tree Collapse file tree 2 files changed +22
-19
lines changed
commonMain/kotlin/com/diffplug/selfie
commonTest/kotlin/com/diffplug/selfie Expand file tree Collapse file tree 2 files changed +22
-19
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright (C) 2023-2024 DiffPlug
2+ * Copyright (C) 2023-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -249,7 +249,7 @@ class SnapshotReader(val valueReader: SnapshotValueReader) {
249249 require(next.indexOf(' [' ) == - 1 ) {
250250 " Missing root snapshot, square brackets not allowed: '$next '"
251251 }
252- return next
252+ return SnapshotValueReader .nameEsc.unescape( next)
253253 }
254254 fun nextSnapshot (): Snapshot {
255255 val rootName = peekKey()
@@ -267,7 +267,9 @@ class SnapshotReader(val valueReader: SnapshotValueReader) {
267267 val facetEndIdx = nextKey.indexOf(' ]' , facetIdx + 1 )
268268 require(facetEndIdx != - 1 ) { " Missing ] in $nextKey " }
269269 val facetName = nextKey.substring(facetIdx + 1 , facetEndIdx)
270- snapshot = snapshot.plusFacet(facetName, valueReader.nextValue())
270+ snapshot =
271+ snapshot.plusFacet(
272+ SnapshotValueReader .nameEsc.unescape(facetName), valueReader.nextValue())
271273 }
272274 }
273275 fun skipSnapshot () {
@@ -357,7 +359,7 @@ class SnapshotValueReader(val lineReader: LineReader) {
357359 } else if (key.endsWith(" " )) {
358360 throw ParseException (lineReader, " Trailing spaces are disallowed: '$key '" )
359361 } else {
360- nameEsc.unescape( key)
362+ key
361363 }
362364 }
363365 private fun nextLine (): String? {
Original file line number Diff line number Diff line change 11/*
2- * Copyright (C) 2023-2024 DiffPlug
2+ * Copyright (C) 2023-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -92,31 +92,32 @@ class SnapshotFileTest {
9292 .trimIndent()
9393 }
9494
95- @Test
96- fun escapingBug () {
97- val file =
98- SnapshotFile .parse(
99- SnapshotValueReader .of(
100- """
95+ @Test
96+ fun escapingBug () {
97+ val file =
98+ SnapshotFile .parse(
99+ SnapshotValueReader .of(
100+ """
101101╔═ trialStarted/stripe ═╗
102102
103103╔═ trialStarted/stripe[«1»{\n "params": {\n "line_items": "line_items=\({quantity=1, price=price_xxxx}\)"\n },\n "apiMode": "V1"\n}] ═╗
104104{}
105105╔═ [end of file] ═╗
106106
107107"""
108- .trimIndent()))
109- val keys = file.snapshots.keys.toList()
110- keys.size shouldBe 1
111- keys[0 ] shouldBe " trialStarted/stripe"
112- val snapshot = file.snapshots.get(keys[0 ])!!
108+ .trimIndent()))
109+ val keys = file.snapshots.keys.toList()
110+ keys.size shouldBe 1
111+ keys[0 ] shouldBe " trialStarted/stripe"
112+ val snapshot = file.snapshots.get(keys[0 ])!!
113113
114- snapshot.facets.keys.size shouldBe 1
115- snapshot.facets.keys.first() shouldBe """ «1»{
114+ snapshot.facets.keys.size shouldBe 1
115+ snapshot.facets.keys.first() shouldBe
116+ """ «1»{
116117 "params": {
117118 "line_items": "line_items=[{quantity=1, price=price_xxxx}]"
118119 },
119120 "apiMode": "V1"
120121}"""
121- }
122+ }
122123}
You can’t perform that action at this time.
0 commit comments