@@ -162,6 +162,38 @@ describe('rest-api as anonymous (data)', () => {
162162
163163 await request . get ( '/db/test/entry/B/my%2Battachment.txt' ) . expect ( 404 ) ;
164164 } ) ;
165+
166+ test ( 'handle attachment names with unescaped slashes' , async ( ) => {
167+ await authenticateAs ( request , '[email protected] ' , '123' ) ; 168+ // The attachment name intentionally has an encoded "/" to make sure URLs are
169+ // correctly encoded and decoded by the API.
170+ let res = await request
171+ . put ( '/db/test/entry/B/my/attachment.txt' )
172+ . set ( 'Content-Type' , 'text/plain' )
173+ . set ( 'Accept' , 'application/json' )
174+ . send ( 'rest-on-couch!!' )
175+ . expect ( 200 ) ;
176+
177+ expect ( res . body . id ) . toBe ( 'B' ) ;
178+
179+ // Unescaped
180+ res = await request . get ( '/db/test/entry/B/my/attachment.txt' ) ;
181+ expect ( res . text ) . toBe ( 'rest-on-couch!!' ) ;
182+ expect ( res . headers [ 'content-type' ] ) . toBe ( 'text/plain' ) ;
183+
184+ // Escaped
185+ res = await request . get ( '/db/test/entry/B/my%2Fattachment.txt' ) ;
186+ expect ( res . text ) . toBe ( 'rest-on-couch!!' ) ;
187+
188+ await authenticateAs ( request , '[email protected] ' , '123' ) ; 189+ await request
190+ . delete ( '/db/test/entry/B/my/attachment.txt' )
191+ . send ( )
192+ . expect ( 200 ) ;
193+ await logout ( request ) ;
194+
195+ await request . get ( '/db/test/entry/B/my/attachment.txt' ) . expect ( 404 ) ;
196+ } ) ;
165197} ) ;
166198
167199describe ( 'basic rest-api as [email protected] (data)' , ( ) => {
0 commit comments