Uploaded image for project: 'Configuration Persistence Service'
  1. Configuration Persistence Service
  2. CPS-1756

Escape special characters in SQL queries using LIKE operator

XMLWordPrintable

      In some SQL queries, we are using user-supplied strings as patterns for LIKE operator. These user strings need to have special characters escaped, or risk returning incorrect results.

      The special characters for LIKE are % and _

      As an example, the contains query implementation uses:

      AND attributes ->> :containsLeafName LIKE CONCAT('%',:containsValue,'%')

      If the user supplies a Cps Path containing %, it will return incorrect results:

      //books[contains(@title,"%")]

      This would return all books instead of no books, as the pattern would expand to %%%.

            danielhanrahan Daniel Hanrahan
            danielhanrahan Daniel Hanrahan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: