@Test public void escapeNonAlphanumericStrings() throws Exception { assertThat(formatter.escape("abc12_A"), is("abc12_A")); assertThat(formatter.escape("Åbc12_A"), is("Åbc12_A")); assertThat(formatter.escape("\0"), is("`\0`")); assertThat(formatter.escape("\n"), is("`\n`")); assertThat(formatter.escape("comma, separated"), is("`comma, separated`")); assertThat(formatter.escape("escaped content `back ticks #"), is("`escaped content ``back ticks #`")); assertThat(formatter.escape("escaped content two `back `ticks"), is("`escaped content two ``back ``ticks`")); }
@Nonnull public static String escape(@Nonnull String string) { Matcher alphaNumericMatcher = ALPHA_NUMERIC.matcher(string); if (!alphaNumericMatcher.matches()) { String reEscapeBackTicks = string.replaceAll(BACKTICK, BACKTICK + BACKTICK); return BACKTICK + reEscapeBackTicks + BACKTICK; } return string; }
CypherVariablesFormatter { @Nonnull public static String escape(@Nonnull String string) { Matcher alphaNumericMatcher = ALPHA_NUMERIC.matcher(string); if (!alphaNumericMatcher.matches()) { String reEscapeBackTicks = string.replaceAll(BACKTICK, BACKTICK + BACKTICK); return BACKTICK + reEscapeBackTicks + BACKTICK; } return string; } }
CypherVariablesFormatter { @Nonnull public static String escape(@Nonnull String string) { Matcher alphaNumericMatcher = ALPHA_NUMERIC.matcher(string); if (!alphaNumericMatcher.matches()) { String reEscapeBackTicks = string.replaceAll(BACKTICK, BACKTICK + BACKTICK); return BACKTICK + reEscapeBackTicks + BACKTICK; } return string; }  }
CypherVariablesFormatter { @Nonnull public static String escape(@Nonnull String string) { Matcher alphaNumericMatcher = ALPHA_NUMERIC.matcher(string); if (!alphaNumericMatcher.matches()) { String reEscapeBackTicks = string.replaceAll(BACKTICK, BACKTICK + BACKTICK); return BACKTICK + reEscapeBackTicks + BACKTICK; } return string; }  @Nonnull static String escape(@Nonnull String string); @Nonnull static String unescapedCypherVariable(@Nonnull String string); }
CypherVariablesFormatter { @Nonnull public static String escape(@Nonnull String string) { Matcher alphaNumericMatcher = ALPHA_NUMERIC.matcher(string); if (!alphaNumericMatcher.matches()) { String reEscapeBackTicks = string.replaceAll(BACKTICK, BACKTICK + BACKTICK); return BACKTICK + reEscapeBackTicks + BACKTICK; } return string; }  @Nonnull static String escape(@Nonnull String string); @Nonnull static String unescapedCypherVariable(@Nonnull String string);  }