diff --git a/lib/src/main/java/de/kuschku/libquassel/util/ExpressionMatch.kt b/lib/src/main/java/de/kuschku/libquassel/util/ExpressionMatch.kt index 6a9e3b8b763b323e8e0a3d3b406b6b77ab8f1bc7..47fd06f349c9c8b68f8d90cd0e8c2ccb2ee6f61f 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/ExpressionMatch.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/ExpressionMatch.kt @@ -233,7 +233,7 @@ class ExpressionMatch : Serializable { } } - if (_sourceExpressionEmpty && !isValid()) { + if (!isValid()) { // This can happen with invalid regex, so make it a bit more user-friendly. Set it to Info // level as ideally someone's not just going to leave a broken match rule around. For // MatchRegEx, they probably need to fix their regex rule. For the other modes, there's @@ -463,7 +463,7 @@ class ExpressionMatch : Serializable { 1, 2 -> { // "\!" -> Elsewhere: keep as "\!" // "\\!" -> Elsewhere: keep as "\\!" - curString += """\""".repeat(consecutiveSlashes) + curString += """\""".repeat(consecutiveSlashes) + "!" } else -> { // This shouldn't ever happen (even with invalid wildcard rules), log a warning @@ -718,7 +718,7 @@ class ExpressionMatch : Serializable { * @see ExpressionMatch::convertFromWildcard() * @return QString with all regular expression characters escaped */ - fun wildcardToRegEx(expression: String): String { + private fun wildcardToRegEx(expression: String): String { // Convert the wildcard expression into regular expression format // We're taking a little bit different of a route... diff --git a/lib/src/test/java/de/kuschku/libquassel/util/ExpressionMatchTest.kt b/lib/src/test/java/de/kuschku/libquassel/util/ExpressionMatchTest.kt index d875f7801e646d62adaa6b891234398c1cc4135e..5ee09e9e4c28c2db9a5d1351356c76abafb0f98d 100644 --- a/lib/src/test/java/de/kuschku/libquassel/util/ExpressionMatchTest.kt +++ b/lib/src/test/java/de/kuschku/libquassel/util/ExpressionMatchTest.kt @@ -193,7 +193,6 @@ class ExpressionMatchTest { @Test fun matchMultiWildcard() { - /* // Simple wildcards, case-insensitive val simpleMatch = ExpressionMatch("?test*;another?", @@ -202,12 +201,10 @@ class ExpressionMatchTest { val simpleMatchCS = ExpressionMatch("?test*;another?", ExpressionMatch.MatchMode.MatchMultiWildcard, true) - */ // Escaped wildcards, case-insensitive val simpleMatchEscape = ExpressionMatch("""\?test\*\;*thing\*""", ExpressionMatch.MatchMode.MatchMultiWildcard, false) - /* // Inverted wildcards, case-insensitive val simpleMatchInvert = ExpressionMatch("""test*;!testing""", @@ -217,7 +214,12 @@ class ExpressionMatchTest { ExpressionMatch("""!testing*""", ExpressionMatch.MatchMode.MatchMultiWildcard, false) // Complex wildcard - val complexMatchFull = """norm;!invert; norm-space ; !invert-space ;;!;\!norm-escaped;\\!slash-invert;\\\\double; escape\;sep;slash-end-split\\;quad\\\\!noninvert;newline-split\nnewline-split-slash\\\nslash-at-end\\""" + val complexMatchFull = """norm;!invert; norm-space ; !invert-space ;;!;\!norm-escaped;""" + + """\\!slash-invert;\\\\double; escape\;sep;slash-end-split\\;""" + + """quad\\\\!noninvert;newline-split""" + "\n" + + """newline-split-slash\\""" + "\n" + + """slash-at-end\\""" + // Match normal components val complexMatchNormal = listOf( """norm""", @@ -234,8 +236,8 @@ class ExpressionMatchTest { ) // Match negating components val complexMatchInvert = listOf( - """(invert)""", - """(invert-space)""" + """invert""", + """invert-space""" ) val complexMatch = ExpressionMatch(complexMatchFull, ExpressionMatch.MatchMode.MatchMultiWildcard, @@ -260,10 +262,8 @@ class ExpressionMatchTest { assertTrue(simpleMatch.match("@testing")) assertTrue(simpleMatch.match("!test")) assertTrue(simpleMatch.match("anotherA")) - */ assertTrue(simpleMatchEscape.match("?test*;thing*")) assertTrue(simpleMatchEscape.match("?test*;AAAAAthing*")) - /* assertTrue(simpleMatchInvert.match("test")) assertTrue(simpleMatchInvert.match("testing things")) // Assert implicit wildcard succeeds @@ -274,10 +274,8 @@ class ExpressionMatchTest { assertFalse(simpleMatch.match("anotherBB")) // Assert unrelated fails assertFalse(simpleMatch.match("not above")) - */ // Assert escaped wildcard fails assertFalse(simpleMatchEscape.match("@testing")) - /* // Assert inverted match fails assertFalse(simpleMatchInvert.match("testing")) assertFalse(simpleMatchImplicit.match("testing")) @@ -303,7 +301,6 @@ class ExpressionMatchTest { assertFalse(complexMatch.match(complexMatchFull)) // Assert complex unrelated not match assertFalse(complexMatch.match("other")) - */ } @Test