@@ -317,10 +317,10 @@ public String combine(String pattern1, String pattern2) {
317
317
if (!StringUtils .hasText (pattern1 ) && !StringUtils .hasText (pattern2 )) {
318
318
return "" ;
319
319
}
320
- else if (!StringUtils .hasText (pattern1 )) {
320
+ if (!StringUtils .hasText (pattern1 )) {
321
321
return pattern2 ;
322
322
}
323
- else if (!StringUtils .hasText (pattern2 )) {
323
+ if (!StringUtils .hasText (pattern2 )) {
324
324
return pattern1 ;
325
325
}
326
326
@@ -330,55 +330,37 @@ else if (!StringUtils.hasText(pattern2)) {
330
330
// However /user + /user -> /usr/user ; /{foo} + /bar -> /{foo}/bar
331
331
return pattern2 ;
332
332
}
333
- else if (pattern1 .endsWith ("/*" )) {
334
- if (pattern2 .startsWith ("/" )) {
335
- // /hotels/* + /booking -> /hotels/booking
336
- return pattern1 .substring (0 , pattern1 .length () - 1 ) + pattern2 .substring (1 );
337
- }
338
- else {
339
- // /hotels/* + booking -> /hotels/booking
340
- return pattern1 .substring (0 , pattern1 .length () - 1 ) + pattern2 ;
341
- }
333
+
334
+ // /hotels/* + /booking -> /hotels/booking
335
+ // /hotels/* + booking -> /hotels/booking
336
+ if (pattern1 .endsWith ("/*" )) {
337
+ return slashConcat (pattern1 .substring (0 , pattern1 .length () - 2 ), pattern2 );
342
338
}
343
- else if (pattern1 .endsWith ("/**" )) {
344
- if (pattern2 .startsWith ("/" )) {
345
- // /hotels/** + /booking -> /hotels/**/booking
346
- return pattern1 + pattern2 ;
347
- }
348
- else {
349
- // /hotels/** + booking -> /hotels/**/booking
350
- return pattern1 + "/" + pattern2 ;
351
- }
339
+
340
+ // /hotels/** + /booking -> /hotels/**/booking
341
+ // /hotels/** + booking -> /hotels/**/booking
342
+ if (pattern1 .endsWith ("/**" )) {
343
+ return slashConcat (pattern1 , pattern2 );
352
344
}
353
- else {
354
- int dotPos1 = pattern1 .indexOf ('.' );
355
- if (dotPos1 == -1 || pattern1ContainsUriVar ) {
356
- // simply concatenate the two patterns
357
- if (pattern1 .endsWith ("/" ) || pattern2 .startsWith ("/" )) {
358
- return pattern1 + pattern2 ;
359
- }
360
- else {
361
- return pattern1 + "/" + pattern2 ;
362
- }
363
- }
364
- String fileName1 = pattern1 .substring (0 , dotPos1 );
365
- String extension1 = pattern1 .substring (dotPos1 );
366
- String fileName2 ;
367
- String extension2 ;
368
- int dotPos2 = pattern2 .indexOf ('.' );
369
- if (dotPos2 != -1 ) {
370
- fileName2 = pattern2 .substring (0 , dotPos2 );
371
- extension2 = pattern2 .substring (dotPos2 );
372
- }
373
- else {
374
- fileName2 = pattern2 ;
375
- extension2 = "" ;
376
- }
377
- String fileName = fileName1 .endsWith ("*" ) ? fileName2 : fileName1 ;
378
- String extension = extension1 .startsWith ("*" ) ? extension2 : extension1 ;
379
345
380
- return fileName + extension ;
346
+ int starDotPos1 = pattern1 .indexOf ("*." );
347
+ if (pattern1ContainsUriVar || starDotPos1 == -1 ) {
348
+ // simply concatenate the two patterns
349
+ return slashConcat (pattern1 , pattern2 );
350
+ }
351
+ String extension1 = pattern1 .substring (starDotPos1 + 1 );
352
+ int dotPos2 = pattern2 .indexOf ('.' );
353
+ String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2 .substring (0 , dotPos2 ));
354
+ String extension2 = (dotPos2 == -1 ? "" : pattern2 .substring (dotPos2 ));
355
+ String extension = extension1 .startsWith ("*" ) ? extension2 : extension1 ;
356
+ return fileName2 + extension ;
357
+ }
358
+
359
+ private String slashConcat (String path1 , String path2 ) {
360
+ if (path1 .endsWith ("/" ) || path2 .startsWith ("/" )) {
361
+ return path1 + path2 ;
381
362
}
363
+ return path1 + "/" + path2 ;
382
364
}
383
365
384
366
/**
0 commit comments