Skip to content

getUnquotedStatementFragments breaks on ESCAPE '\' #3640

@rullzer

Description

@rullzer

I encountered an issue where not all the parameters would be replaced correctly.

The query in question is:

SELECT "f".*
FROM "oc_filecache" "f" 
WHERE 
(
  (
    ("f"."storage" = :dcValue1) AND ("f"."path" LIKE :dcValue2 ESCAPE '\')
  ) OR (
    ("f"."storage" = :dcValue3) AND ("f"."path" LIKE :dcValue4 ESCAPE '\')
  ) OR (
    "f"."storage" = :dcValue5
  )
) AND (
  ("f"."mimetype" <> :dcValue6) OR ("f"."size" = 0)
) AND (
  "f"."path" NOT LIKE :dcValue7
) AND (
  "f"."path" NOT LIKE :dcValue8
)
ORDER BY "f"."mtime"
DESC LIMIT 500

Manually replacing all the values runs this like a charm.
However it seems the split in getUnquotedStatementFragments doesn't like ESCAPING on \.

What happens is that :dcValue1 and :dcValue2 are properly found.
However then the regex interpets the \' as an escaped quote. Thus ignoring until the next escape statement.

The replaces statement thus looks like

SELECT "f".*
FROM "oc_filecache" "f"
WHERE 
(
  (
    ("f"."storage" = ?) AND ("f"."path" LIKE ? ESCAPE "\")
  ) OR (
    ("f"."storage" = :dcValue3) AND ("f"."path" LIKE :dcValue4 ESCAPE "\")
  ) OR (
    "f"."storage" = :dcValue5
  )
) AND (
  ("f"."mimetype" <> :dcValue6) OR ("f"."size" = 0)
) AND (
  "f"."path" NOT LIKE :dcValue7
) AND (
  "f"."path" NOT LIKE :dcValue8
)
ORDER BY "f"."mtime"
DESC LIMIT 500

I'll try to dig a bit deeper or to come up with a PR that at least provides you with failing test cases to verify.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions