1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Jonathan Hefner 2022-03-23 13:31:34 -05:00
parent 02ad57a46b
commit 659cdebc68

View file

@ -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"