Some specific truncated strings are not matched via LIKE expression in SQL

I seem to not be able to debug it, there is a binary encoded BitTorrent info-hash string truncated to 20 bytes (Sha1), the length of string in db is 32 bytes (sha2), so I do LIKE expression this way:

if (strlen($info_hash) == 32) {
    $is_bt_v2 = true;
} elseif (strlen($info_hash) == 20) {
    $is_bt_v2 = false;
}
$info_hash = rtrim(DB()->escape($info_hash), ' ');

$info_hash_where = $is_bt_v2 ? "WHERE tor.info_hash_v2 = '$info_hash'" : "WHERE tor.info_hash = '$info_hash' OR tor.info_hash_v2 LIKE '$info_hash%'";

$sql = "
    SELECT tor.topic_id, tor.poster_id, tor.tor_type, tor.info_hash, tor.info_hash_v2, u.*
    FROM " . BB_BT_TORRENTS . " tor
    LEFT JOIN " . BB_BT_USERS . " u ON u.auth_key = '$passkey_sql'
    $info_hash_where
    LIMIT 1
";
$row = DB()->fetch_row($sql);

$is_bt_v2 is just a marker with checked length of hash string, so it will be true if hash length will be 32 bytes in the future (currently not supported by standard) and the search will be performed only in v2 column for performance, else it first will be checked in v1 then v2 via LIKE expression.

In reality hash is always truncated to 20 bytes even if it is sha2, so it is being checked in both columns (only the second condition in $info_hash_where).

The thing is, if I search full 32 bytes string it will return the result, somehow it works with other v2 strings truncated to 20 bytes, but some specific strings are not found.

I spent a week checking the db settings (MariaDb), but I don’t know what is happening.

Strings (v2):

Full: 97978479e7eba00af6f24953f6b94b229b556627167b710472ad4c9bc4ceac41 // Works

Truncated: 97978479e7eba00af6f24953f6b94b229b556627 // Works

Url encoded: %97%97%84y%e7%eb%a0%0a%f6%f2IS%f6%b9K%22%9bUf%27


Full: b5c69a98c0235cc2af0fa0c956a2984dc10410b1ab0eee46c9cb0c876d0c5189 // Works

Truncated: b5c69a98c0235cc2af0fa0c956a2984dc10410b1 // DOESN’T WORK!

Url encoded: %b5%c6%9a%98%c0%23%5c%c2%af%0f%a0%c9V%a2%98M%c1%04%10%b1