@@ -203,47 +203,61 @@ func TestPrefix(t *testing.T) {
203
203
}
204
204
205
205
func TestFilenameEscape (t * testing.T ) {
206
- re := regexp .MustCompile (`<D:href>([^<]*)</D:href>` )
207
- do := func (method , urlStr string ) (string , error ) {
206
+ hrefRe := regexp .MustCompile (`<D:href>([^<]*)</D:href>` )
207
+ displayNameRe := regexp .MustCompile (`<D:displayname>([^<]*)</D:displayname>` )
208
+ do := func (method , urlStr string ) (string , string , error ) {
208
209
req , err := http .NewRequest (method , urlStr , nil )
209
210
if err != nil {
210
- return "" , err
211
+ return "" , "" , err
211
212
}
212
213
res , err := http .DefaultClient .Do (req )
213
214
if err != nil {
214
- return "" , err
215
+ return "" , "" , err
215
216
}
216
217
defer res .Body .Close ()
217
218
218
219
b , err := ioutil .ReadAll (res .Body )
219
220
if err != nil {
220
- return "" , err
221
+ return "" , "" , err
221
222
}
222
- m := re .FindStringSubmatch (string (b ))
223
- if len (m ) != 2 {
224
- return "" , errors .New ("D:href not found" )
223
+ hrefMatch := hrefRe .FindStringSubmatch (string (b ))
224
+ if len (hrefMatch ) != 2 {
225
+ return "" , "" , errors .New ("D:href not found" )
226
+ }
227
+ displayNameMatch := displayNameRe .FindStringSubmatch (string (b ))
228
+ if len (displayNameMatch ) != 2 {
229
+ return "" , "" , errors .New ("D:displayname not found" )
225
230
}
226
231
227
- return m [1 ], nil
232
+ return hrefMatch [ 1 ], displayNameMatch [1 ], nil
228
233
}
229
234
230
235
testCases := []struct {
231
- name , want string
236
+ name , wantHref , wantDisplayName string
232
237
}{{
233
- name : `/foo%bar` ,
234
- want : `/foo%25bar` ,
238
+ name : `/foo%bar` ,
239
+ wantHref : `/foo%25bar` ,
240
+ wantDisplayName : `foo%bar` ,
241
+ }, {
242
+ name : `/こんにちわ世界` ,
243
+ wantHref : `/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E4%B8%96%E7%95%8C` ,
244
+ wantDisplayName : `こんにちわ世界` ,
235
245
}, {
236
- name : `/こんにちわ世界` ,
237
- want : `/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F%E4%B8%96%E7%95%8C` ,
246
+ name : `/Program Files/` ,
247
+ wantHref : `/Program%20Files` ,
248
+ wantDisplayName : `Program Files` ,
238
249
}, {
239
- name : `/Program Files/` ,
240
- want : `/Program%20Files` ,
250
+ name : `/go+lang` ,
251
+ wantHref : `/go+lang` ,
252
+ wantDisplayName : `go+lang` ,
241
253
}, {
242
- name : `/go+lang` ,
243
- want : `/go+lang` ,
254
+ name : `/go&lang` ,
255
+ wantHref : `/go&lang` ,
256
+ wantDisplayName : `go&lang` ,
244
257
}, {
245
- name : `/go&lang` ,
246
- want : `/go&lang` ,
258
+ name : `/go<lang` ,
259
+ wantHref : `/go%3Clang` ,
260
+ wantDisplayName : `go<lang` ,
247
261
}}
248
262
fs := NewMemFS ()
249
263
for _ , tc := range testCases {
@@ -273,13 +287,16 @@ func TestFilenameEscape(t *testing.T) {
273
287
274
288
for _ , tc := range testCases {
275
289
u .Path = tc .name
276
- got , err := do ("PROPFIND" , u .String ())
290
+ gotHref , gotDisplayName , err := do ("PROPFIND" , u .String ())
277
291
if err != nil {
278
292
t .Errorf ("name=%q: PROPFIND: %v" , tc .name , err )
279
293
continue
280
294
}
281
- if got != tc .want {
282
- t .Errorf ("name=%q: got %q, want %q" , tc .name , got , tc .want )
295
+ if gotHref != tc .wantHref {
296
+ t .Errorf ("name=%q: got href %q, want %q" , tc .name , gotHref , tc .wantHref )
297
+ }
298
+ if gotDisplayName != tc .wantDisplayName {
299
+ t .Errorf ("name=%q: got dispayname %q, want %q" , tc .name , gotDisplayName , tc .wantDisplayName )
283
300
}
284
301
}
285
302
}
0 commit comments