function createURIFilterString()

in src/QueryEditor.tsx [90:133]


  function createURIFilterString(queryText: string) {
    // Split query string into multiple strings for each part of the filter
    let queryFilters = queryText.match(/(?:[^\s"]+|"(?:\\"|[^"])*")+/g)
    // From each filter part, create Google Cloud Trace URI string portion to match it
    let uriFilterMaps = queryFilters?.map(filterItem => {
      let key = filterItem.substring(0, filterItem.indexOf(":"));
      let value = filterItem.substring(filterItem.indexOf(":") + 1, filterItem.length);

      if (key.toLowerCase() === "label") {
        key = `${key}:${value.substring(0, value.indexOf(":"))}`
        value = value.substring(value.indexOf(":") + 1, value.length);
      }
      
      let specialChars = ""
      // Attempt to grab any special chars (+ or ^) so we can tack them on after removing quotes
      if (value.length > 1) {
        let firstChar = value.charAt(0)
        let secondChar = value.charAt(1)

        // Move specials chars from the front of value to key for Google Cloud Trace compatibility
        if ((firstChar === "^" && secondChar === "+") || (firstChar === "+" && secondChar === "^")) {
          specialChars = "^+"
          value = value.substring(2, value.length)
        } else if (firstChar === "+" || firstChar === "^") {
          specialChars = firstChar
          value = value.substring(1, value.length)
        }
      }

      // Remove any quotes from value as these cause issues with the URI
      value = value.replace(/(^"|"$)/g, '')
      // Re-add any special characters if any
      value = specialChars + value
      // Convert escaped quotes in value to underscore Hex values for URI compatibility
      value = value.replace(/\\"/gi, "_5C_5C_5C_22")
      // Convert + in value to underscore Hex values for URI compatibility
      value = value.replace("+", "%2B")

      // Return the complete URI portion for this part of the filter
      return `{_22k_22_3A_22${key}_22_2C_22t_22_3A10_2C_22v_22_3A_22_5C_22${value}_5C_22_22}`
    })

    return uriFilterMaps?.join(",")
  }