Skip to content

Commit

Permalink
Merge pull request #6 from alenon/develop
Browse files Browse the repository at this point in the history
fixed bug: regex is cut
  • Loading branch information
alenon committed Mar 28, 2018
2 parents 2d3cb03 + e92fc93 commit d24e69d
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 d24e69d

Please sign in to comment.