Raised This Month: $ Target: $400
 0% 

Solved Database.Escape weird result


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
N0B0DY1x
Junior Member
Join Date: Jul 2014
Location: France
Old 05-05-2020 , 16:10   Database.Escape weird result
Reply With Quote #1

Hi there,

I'm using LevelsRanks plugin on my CS:GO server and I'm facing weird strings in my database caused by the Database.Escape() function.

My ingame name is "No'". When I use the Database.Escape() function onto it, the output is "No\'" which is ok.

But A guy came with this name : "Everything's gonna be alright" and the Database.Escape() output was "Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\ \\\". Which is really weird.

Somes other guys have this issue and it seems to appen when you have a quote in your name, everythings behind it is replaced with backslashs and quote (the pattern seems random aswell).

Anyone got this error ? Seems to be a Sourcemod bug. I'm using SM 1.10.0 6488 (the latest) and used 6482 before (both have the issue). I'm here because I can't find anything on the forum and on github, am I the first guy to get this error ? Or its just a scripting issue ?

So here's a little script I wrote to test the escape function (I used the levels_ranks database config but you can use anything you want to test, for me its a mysql database). This script uses the levels_ranks buffers size.

PHP Code:
#include <sourcemod>

public Plugin myinfo =
{
    
name "Database.Escape test",
    
author "Nobody-x",
    
version "1"
};

Database g_hDatabase;

public 
void OnPluginStart() {
    
Database.Connect(OnDBConnect"levels_ranks");

    
RegConsoleCmd("sm_test"Cmd_Test)
    
RegConsoleCmd("sm_test2"Cmd_Test2)
}

Action Cmd_Test(int clientint args) {
    if (
g_hDatabase == null) {
        return 
Plugin_Continue;
    }

    
char sName[65];
    
GetClientName(clientsName32);

    
LogMessage("Client name : \"%s\""sName);

    
g_hDatabase.Escape(sNamesNamesizeof(sName));

    
LogMessage("Escaped name : \"%s\""sName);

    return 
Plugin_Changed;
}

Action Cmd_Test2(int clientint args) {
    if (
g_hDatabase == null) {
        return 
Plugin_Continue;
    }

    
char sName[65];
    
GetClientName(clientsName32);

    
LogMessage("Client name : \"%s\""sName);

    
SQL_EscapeString(g_hDatabasesNamesNamesizeof(sName));

    
LogMessage("Escaped name : \"%s\""sName);

    return 
Plugin_Changed;
}

public 
void OnDBConnect(Database db, const char[] errorany data)
{
    if (
db == null)
    {
        
LogError("Database failure: %s"error);
        return;
    }

    
g_hDatabase db;

Edit:

These are the outputs of both commands :

Code:
L 05/05/2020 - 22:04:30: [test_escape.smx] Client name : "Everything's gonna be alright"
L 05/05/2020 - 22:04:30: [test_escape.smx] Escaped name : "Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\\\\"
L 05/05/2020 - 22:04:32: [test_escape.smx] Client name : "Everything's gonna be alright"
L 05/05/2020 - 22:04:32: [test_escape.smx] Escaped name : "Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\\\\"

L 05/05/2020 - 22:04:08: [test_escape.smx] Client name : "No'"
L 05/05/2020 - 22:04:08: [test_escape.smx] Escaped name : "No\'"
L 05/05/2020 - 22:04:11: [test_escape.smx] Client name : "No'"
L 05/05/2020 - 22:04:11: [test_escape.smx] Escaped name : "No\'"

Last edited by N0B0DY1x; 05-05-2020 at 18:36. Reason: Solved
N0B0DY1x is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode