|
1 | 1 | /* |
2 | | - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2017 the original author or authors. |
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. |
@@ -220,8 +220,7 @@ protected boolean doMatch(String pattern, String path, boolean fullMatch, Map<St |
220 | 220 | if (pathIdxStart > pathIdxEnd) { |
221 | 221 | // Path is exhausted, only match if rest of pattern is * or **'s |
222 | 222 | if (pattIdxStart > pattIdxEnd) { |
223 | | - return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator) : |
224 | | - !path.endsWith(this.pathSeparator)); |
| 223 | + return (pattern.endsWith(this.pathSeparator) == path.endsWith(this.pathSeparator)); |
225 | 224 | } |
226 | 225 | if (!fullMatch) { |
227 | 226 | return true; |
@@ -318,34 +317,32 @@ else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) { |
318 | 317 |
|
319 | 318 | private boolean isPotentialMatch(String path, String[] pattDirs) { |
320 | 319 | if (!this.trimTokens) { |
321 | | - char[] pathChars = path.toCharArray(); |
322 | 320 | int pos = 0; |
323 | 321 | for (String pattDir : pattDirs) { |
324 | 322 | int skipped = skipSeparator(path, pos, this.pathSeparator); |
325 | 323 | pos += skipped; |
326 | | - skipped = skipSegment(pathChars, pos, pattDir); |
| 324 | + skipped = skipSegment(path, pos, pattDir); |
327 | 325 | if (skipped < pattDir.length()) { |
328 | | - if (skipped > 0) { |
329 | | - return true; |
330 | | - } |
331 | | - return (pattDir.length() > 0) && isWildcardChar(pattDir.charAt(0)); |
| 326 | + return (skipped > 0 || (pattDir.length() > 0 && isWildcardChar(pattDir.charAt(0)))); |
332 | 327 | } |
333 | 328 | pos += skipped; |
334 | 329 | } |
335 | 330 | } |
336 | 331 | return true; |
337 | 332 | } |
338 | 333 |
|
339 | | - private int skipSegment(char[] chars, int pos, String prefix) { |
| 334 | + private int skipSegment(String path, int pos, String prefix) { |
340 | 335 | int skipped = 0; |
341 | | - for (char c : prefix.toCharArray()) { |
| 336 | + for (int i = 0; i < prefix.length(); i++) { |
| 337 | + char c = prefix.charAt(i); |
342 | 338 | if (isWildcardChar(c)) { |
343 | 339 | return skipped; |
344 | 340 | } |
345 | | - else if (pos + skipped >= chars.length) { |
| 341 | + int currPos = pos + skipped; |
| 342 | + if (currPos >= path.length()) { |
346 | 343 | return 0; |
347 | 344 | } |
348 | | - else if (chars[pos + skipped] == c) { |
| 345 | + if (c == path.charAt(currPos)) { |
349 | 346 | skipped++; |
350 | 347 | } |
351 | 348 | } |
|
0 commit comments