@Test public void escapeLeavesSupportedSpecialCharactersUnescaped() { String supportedSpecialCharacters = "?*\"\""; assertThat(searchContributionSupport.escape(supportedSpecialCharacters), is(supportedSpecialCharacters)); }
public String escape(String value) { if (null == value) { return null; } String escaped = QueryParserBase.escape(value); boolean shouldLeaveDoubleQuotesEscaped = StringUtils.countMatches(value, "\"") % 2 != 0; String escapedCharactersRegex = shouldLeaveDoubleQuotesEscaped ? "\\\\([?*])" : "\\\\([?*\"])"; return escaped.replaceAll(escapedCharactersRegex, "$1"); }
SearchContributionSupport implements SearchContribution { public String escape(String value) { if (null == value) { return null; } String escaped = QueryParserBase.escape(value); boolean shouldLeaveDoubleQuotesEscaped = StringUtils.countMatches(value, "\"") % 2 != 0; String escapedCharactersRegex = shouldLeaveDoubleQuotesEscaped ? "\\\\([?*])" : "\\\\([?*\"])"; return escaped.replaceAll(escapedCharactersRegex, "$1"); } }
SearchContributionSupport implements SearchContribution { public String escape(String value) { if (null == value) { return null; } String escaped = QueryParserBase.escape(value); boolean shouldLeaveDoubleQuotesEscaped = StringUtils.countMatches(value, "\"") % 2 != 0; String escapedCharactersRegex = shouldLeaveDoubleQuotesEscaped ? "\\\\([?*])" : "\\\\([?*\"])"; return escaped.replaceAll(escapedCharactersRegex, "$1"); }  }
SearchContributionSupport implements SearchContribution { public String escape(String value) { if (null == value) { return null; } String escaped = QueryParserBase.escape(value); boolean shouldLeaveDoubleQuotesEscaped = StringUtils.countMatches(value, "\"") % 2 != 0; String escapedCharactersRegex = shouldLeaveDoubleQuotesEscaped ? "\\\\([?*])" : "\\\\([?*\"])"; return escaped.replaceAll(escapedCharactersRegex, "$1"); }  @Override void contribute(final BoolQueryBuilder query, final String type, final String value); String escape(String value); }
SearchContributionSupport implements SearchContribution { public String escape(String value) { if (null == value) { return null; } String escaped = QueryParserBase.escape(value); boolean shouldLeaveDoubleQuotesEscaped = StringUtils.countMatches(value, "\"") % 2 != 0; String escapedCharactersRegex = shouldLeaveDoubleQuotesEscaped ? "\\\\([?*])" : "\\\\([?*\"])"; return escaped.replaceAll(escapedCharactersRegex, "$1"); }  @Override void contribute(final BoolQueryBuilder query, final String type, final String value); String escape(String value);  }