src/main/java/org/folio/rest/utility/FormatUtility.java
public static String normalizeCqlUrlArgument(String text) {
    if (text == null) {
      return "\"\"";
    }

    StringBuilder builder = new StringBuilder(text.length() + 2);

    builder.append('"');
    for (int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);

      switch (c) {
      case '\\':
      case '*':
      case '?':
      case '^':
      case '"':
        builder.append('\\')
          .append(c);
        break;

      default:
        builder.append(c);
      }
    }
    builder.append('"');

    return builder.toString()
      .replace("&", "%26");
  }
/**
   * Escape the text to ensure it can be safely used in CQL.
   *
   * This will escape the CQL and further escape CQL as a URL argument.
   *
   * Perform the most minimalistic URL escaping possible for a single URL Argument.
   *
   * This only escapes what is necessary when passing a URL to an endpoint.
   * So far this only appears to be the ampersand character.
   *
   * Use this instead of URLEncoder.encode(url, StandardCharsets.UTF_8); for when CQL is involved.
   *
   * @param text The text to normalize.
   * @return The normalized text for use inside the CQL as a value.
   *
   * @see https://github.com/folio-org/raml-module-builder/blob/2c39990c96c22262b02c98dd2b51cbeedc90fb9d/util/src/main/java/org/folio/util/StringUtil.java#L39
   */
Escape the text to ensure it can be safely used in CQL.
This will escape the CQL and further escape CQL as a URL argument.

Perform the most minimalistic URL escaping possible for a single URL Argument.

This only escapes what is necessary when passing a URL to an endpoint.
So far this only appears to be the ampersand character.

Use this instead of URLEncoder.encode(url, StandardCharsets.UTF_8); for when CQL is involved.

@param text The text to normalize.
@return The normalized text for use inside the CQL as a value.


Escape the text to ensure it can be safely used in CQL . This will escape the CQL and further escape CQL as a URL argument . Perform the most minimalistic URL escaping possible for a single URL Argument . This only escapes what is necessary when passing a URL to an endpoint . So far this only appears to be the ampersand character . Use this instead of URLEncoder . encode ( url StandardCharsets . UTF_8 ) ; for when CQL is involved . @param text The text to normalize . @return The normalized text for use inside the CQL as a value .
public static String normalizeCqlUrlArgument(String text) {
    if (text == null) {
      return "\"\"";
    }
    StringBuilder builder = new StringBuilder(text.length() + 2);
    builder.append('"');
    for (int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);
      switch (c) {
      case '\\':
      case '*':
      case '?':
      case '^':
      case '"':
        builder.append('\\')
          .append(c);
        break;
      default:
        builder.append(c);
      }
    }
    builder.append('"');
    return builder.toString()
      .replace("&", "%26");
  }
public static String normalizeCqlUrlArgument ( String text ) { if ( text == null ) { return "\"\"" ; } StringBuilder builder = new StringBuilder ( text . length ( ) + 2 ) ; builder . append ( '"' ) ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { char c = text . charAt ( i ) ; switch ( c ) { case '\\' : case '*' : case '?' : case '^' : case '"' : builder . append ( '\\' ) . append ( c ) ; break ; default : builder . append ( c ) ; } } builder . append ( '"' ) ; return builder . toString ( ) . replace ( "&" , "%26" ) ; }
Escape the text to ensure it can be safely used in CQL.
Escape the text to ensure it can be safely used in CQL .