Welcome Guest, Not a member yet? Register   Sign In
BUG: active record like() adds \ before _
#1

[eluser]jmadsen[/eluser]
Just tracked this down, don't have time at the moment to do a full bug report on git but wanted to record/ask before I forget:

Using version 2.1.1, when using active record like() function,

this_is_my_slug

becomes

this\_is\_my\_slug

traced it back to DB_Driver

Code:
function escape_like_str($str)
{
  return $this->escape_str($str, TRUE);
}

followed by the mysql driver, escape_str() function ...

Code:
function escape_str($str, $like = FALSE)
{

...
// escape LIKE condition wildcards
if ($like === TRUE)
{
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}

there's no way to avoid $like = TRUE, and so turn off the added slashes

Has this been seen already for v3.0, or can somebody confirm my findings?

TIA,

Jeff
#2

[eluser]Aken[/eluser]
It's not a bug - the underscore is a special wildcard character when using pattern matching with LIKE. The slashes are used to escape them so they are treated as actual underscore characters.
#3

[eluser]jmadsen[/eluser]
yes, but the bug is you can't turn it off when you don't want to pattern match.

Try doing a " LIKE this_is_underscored%" search - you can't.

At minimum, needs documented
#4

[eluser]Aken[/eluser]
And it has already been addressed in 3.0. The docs could use updating, though.
#5

[eluser]jmadsen[/eluser]
cool - that's what I wanted to check on. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB