Ard Schrijvers pushed to branch release/3.2 at cms-community / hippo-site-toolkit
Commits: 2f00364f by Jasper Floor at 2016-05-30T14:38:23+02:00 HSTTWO-3680 [Backport 3.2] remove trailing - ! when preceded by a space, also remove the space (cherry picked from commit 809e804da36571000393ea3105ec6326ed1619d1) HSTTWO-3680 [Backport 3.2] and also the class that does the work remove trailing - ! when preceded by a space, also remove the space (cherry picked from commit 58b97aa7b27a70ccc1e14e3528df2aec85d2598f) HSTTWO-3680 [Backport 3.2] remove additional whitespaces between words (cherry picked from commit ef7ca48dd350e703c75ceaf65aa2d711d474fca9) - - - - - 2 changed files: - content-beans/src/main/java/org/hippoecm/hst/util/SearchInputParsingUtils.java - content-beans/src/test/java/org/hippoecm/hst/util/TestSearchInputParsingUtils.java Changes: ===================================== content-beans/src/main/java/org/hippoecm/hst/util/SearchInputParsingUtils.java ===================================== --- a/content-beans/src/main/java/org/hippoecm/hst/util/SearchInputParsingUtils.java +++ b/content-beans/src/main/java/org/hippoecm/hst/util/SearchInputParsingUtils.java @@ -207,7 +207,7 @@ public final class SearchInputParsingUtils { } } else { char prevChar = sb.charAt(sb.length() - 1); - if (prevChar == ' ') { + if (prevChar == ' ' && containsNextCharAndIsNotSpecial(input, i)) { sb.append(c); } else if (c == '-') { // check next char : only if next char is again a non-special char we include the '-' @@ -243,7 +243,7 @@ public final class SearchInputParsingUtils { if (!input.equals(output)) { log.debug("Rewrote input '{}' to '{}'", input, output); } - return output; + return compressWhitespace(output); } private static boolean ignoreChar(final char c, final char[] ignore) { ===================================== content-beans/src/test/java/org/hippoecm/hst/util/TestSearchInputParsingUtils.java ===================================== --- a/content-beans/src/test/java/org/hippoecm/hst/util/TestSearchInputParsingUtils.java +++ b/content-beans/src/test/java/org/hippoecm/hst/util/TestSearchInputParsingUtils.java @@ -67,7 +67,7 @@ public class TestSearchInputParsingUtils { // allow wildcard false assertEquals("The quick brown fox jumps over the lazy dog", SearchInputParsingUtils.parse("The ?*qu??ic?k br?ow*?n fo*x jumps over the lazy dog", false)); - assertEquals("The quick brown fox jumps over the lazy dog", SearchInputParsingUtils.parse("The (quick brown) (fox jumps) &( over ] ] [the lazy dog", true)); + assertEquals("The quick brown fox jumps over the lazy dog", SearchInputParsingUtils.parse("The (quick brown) (fox jumps) &( over ] ] [the lazy dog", true)); assertEquals("The -quick brown fox jumps over the lazy dog", SearchInputParsingUtils.parse("The NOT quick brown fox jumps over the lazy dog", true)); @@ -162,4 +162,20 @@ public class TestSearchInputParsingUtils { assertEquals("The &quick brown& fox jumps o&ver &&the l&&azy dog&&", SearchInputParsingUtils.parse("The &quick brown& fox jumps o&ver &&the l&&azy dog&&", true, new char[]{'&'})); assertEquals("The &quick brown& fox jumps o&ver &&the l&&azy dog&&", SearchInputParsingUtils.parse("The &quick brown& fox jumps o&ver &&the l&&azy dog&&", false, new char[]{'&'})); } + + @Test + public void testSearchInputParsingUtils_removeInvalidAndEscapeChars_removesTrailingExclamation() { + assertEquals("No exclamation",SearchInputParsingUtils.removeInvalidAndEscapeChars("No exclamation!", false)); + assertEquals("No exclamation",SearchInputParsingUtils.removeInvalidAndEscapeChars("No exclamation!", true)); + assertEquals("No exclamation",SearchInputParsingUtils.removeInvalidAndEscapeChars("No exclamation !", false)); + assertEquals("No exclamation",SearchInputParsingUtils.removeInvalidAndEscapeChars("No exclamation !", true)); + } + + @Test + public void testSearchInputParsingUtils_removeInvalidAndEscapeChars_removesTrailingDash() { + assertEquals("No dash",SearchInputParsingUtils.removeInvalidAndEscapeChars("No dash-", false)); + assertEquals("No dash",SearchInputParsingUtils.removeInvalidAndEscapeChars("No dash-", true)); + assertEquals("No dash",SearchInputParsingUtils.removeInvalidAndEscapeChars("No dash -", false)); + assertEquals("No dash",SearchInputParsingUtils.removeInvalidAndEscapeChars("No dash -", true)); + } } View it on GitLab: https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/2f00364f87325f0f948c8618c22cff4f40bce992
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn