From 659cdebc682770b2a06fc5a22fc48a89bb7e20dc Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Wed, 23 Mar 2022 13:31:34 -0500 Subject: [PATCH] Fix sanitize_sql_like with escape_character doc [ci-skip] When an `escape_character` is specified, `sanitize_sql_like` will escape occurrences of it rather than `"\\"`. This commit also modifies the examples to demonstrate that behavior. --- activerecord/lib/active_record/sanitization.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 1ab2e81fbd..2105399630 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -92,16 +92,17 @@ module ActiveRecord end # Sanitizes a +string+ so that it is safe to use within an SQL - # LIKE statement. This method uses +escape_character+ to escape all occurrences of "\", "_" and "%". + # LIKE statement. This method uses +escape_character+ to escape all + # occurrences of itself, "_" and "%". # - # sanitize_sql_like("100%") - # # => "100\\%" + # sanitize_sql_like("100% true!") + # # => "100\\% true!" # # sanitize_sql_like("snake_cased_string") # # => "snake\\_cased\\_string" # - # sanitize_sql_like("100%", "!") - # # => "100!%" + # sanitize_sql_like("100% true!", "!") + # # => "100!% true!!" # # sanitize_sql_like("snake_cased_string", "!") # # => "snake!_cased!_string"