Skip to content

Commit

Permalink
fixed bug: if there is only one regular char after special wildcard c…
Browse files Browse the repository at this point in the history
…har than it has been missed from the final regex string
  • Loading branch information
alenon committed Mar 28, 2018
1 parent 711669c commit e92fc93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jwildcard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id "com.jfrog.bintray" version "1.7"
}

version '1.1'
version '1.2'
group 'com.yevdo'

repositories {
Expand Down
2 changes: 1 addition & 1 deletion jwildcard/src/main/java/com/yevdo/jwildcard/JWildcard.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static String getRegexString(String wildcard, List<JWildcardPairWithInde
cursor = index + jWildcardPairWithIndex.getRule().getKey().length();
}

if (cursor < wildcard.length() - 1) {
if (cursor <= wildcard.length() - 1) {
regex.append(Pattern.quote(wildcard.substring(cursor, wildcard.length())));
}
return regex.toString();
Expand Down
14 changes: 13 additions & 1 deletion jwildcard/src/test/groovy/JWildcardSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ class JWildcardSpec extends Specification {

def "convert wildcard to regex"() {
when:
String regex = JWildcard.wildcardToRegex("mywil?card*")
String regex = JWildcard.wildcardToRegex("mywil?c")

then:
regex == "^\\Qmywil\\E.\\Qc\\E\$"

when:
regex = JWildcard.wildcardToRegex("mywil?card*")

then:
regex == "^\\Qmywil\\E.\\Qcard\\E.*\$"
Expand Down Expand Up @@ -105,5 +111,11 @@ class JWildcardSpec extends Specification {

then:
matches

when:
matches = JWildcard.matches("Lond?n", "London")

then:
matches
}
}

0 comments on commit e92fc93

Please sign in to comment.