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 1
1
/*
2
- * Copyright (C) 2023-2024 DiffPlug
2
+ * Copyright (C) 2023-2025 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -249,7 +249,7 @@ class SnapshotReader(val valueReader: SnapshotValueReader) {
249
249
require(next.indexOf(' [' ) == - 1 ) {
250
250
" Missing root snapshot, square brackets not allowed: '$next '"
251
251
}
252
- return next
252
+ return SnapshotValueReader .nameEsc.unescape( next)
253
253
}
254
254
fun nextSnapshot (): Snapshot {
255
255
val rootName = peekKey()
@@ -267,7 +267,9 @@ class SnapshotReader(val valueReader: SnapshotValueReader) {
267
267
val facetEndIdx = nextKey.indexOf(' ]' , facetIdx + 1 )
268
268
require(facetEndIdx != - 1 ) { " Missing ] in $nextKey " }
269
269
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())
271
273
}
272
274
}
273
275
fun skipSnapshot () {
@@ -357,7 +359,7 @@ class SnapshotValueReader(val lineReader: LineReader) {
357
359
} else if (key.endsWith(" " )) {
358
360
throw ParseException (lineReader, " Trailing spaces are disallowed: '$key '" )
359
361
} else {
360
- nameEsc.unescape( key)
362
+ key
361
363
}
362
364
}
363
365
private fun nextLine (): String? {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (C) 2023-2024 DiffPlug
2
+ * Copyright (C) 2023-2025 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -92,31 +92,32 @@ class SnapshotFileTest {
92
92
.trimIndent()
93
93
}
94
94
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
+ """
101
101
╔═ trialStarted/stripe ═╗
102
102
103
103
╔═ trialStarted/stripe[«1»{\n "params": {\n "line_items": "line_items=\({quantity=1, price=price_xxxx}\)"\n },\n "apiMode": "V1"\n}] ═╗
104
104
{}
105
105
╔═ [end of file] ═╗
106
106
107
107
"""
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 ])!!
113
113
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»{
116
117
"params": {
117
118
"line_items": "line_items=[{quantity=1, price=price_xxxx}]"
118
119
},
119
120
"apiMode": "V1"
120
121
}"""
121
- }
122
+ }
122
123
}
You can’t perform that action at this time.
0 commit comments