File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,13 @@ struct JSONPointer {
17
17
}
18
18
19
19
var path : String {
20
- return components. joined ( separator: " / " )
20
+ return components
21
+ . map {
22
+ $0
23
+ . replacingOccurrences ( of: " ~ " , with: " ~0 " )
24
+ . replacingOccurrences ( of: " / " , with: " ~1 " )
25
+ }
26
+ . joined ( separator: " / " )
21
27
}
22
28
23
29
func resolve( document: Any ) -> Any ? {
Original file line number Diff line number Diff line change @@ -115,4 +115,16 @@ class JSONPointerTests: XCTestCase {
115
115
116
116
XCTAssertNil ( pointer. resolve ( document: document) )
117
117
}
118
+
119
+ // MARK: - #path
120
+
121
+ func testPath( ) {
122
+ let pointer = JSONPointer ( path: " /foo " )
123
+ XCTAssertEqual ( pointer. path, " /foo " )
124
+ }
125
+
126
+ func testPathWithSlash( ) {
127
+ let pointer = JSONPointer ( path: " /a~1b " )
128
+ XCTAssertEqual ( pointer. path, " /a~1b " )
129
+ }
118
130
}
You can’t perform that action at this time.
0 commit comments