Support » Plugin: Code Snippets » Percent sign bug

Viewing 8 replies - 1 through 8 (of 8 total)
  • According to function prepare in wp-db.php
    * Literals (%) as parts of the query must be properly written as %%.

    So, i added the following code in code-snippets.php at public function escape_snippet_data
    $snippet->code = str_replace( '%', '%%', $snippet->code );

    Plugin Author Shea Bunge

    (@bungeshea)

    I would have thought this would have been picked up by esc_sql(), which is run on the snippet code. Good work for finding the bug and fixing it! I’ll test this and add it to the next release.

    Plugin Author Shea Bunge

    (@bungeshea)

    Just tried creating a snippet that contains the % character, and it saves fine. Strange that your recieve this error and I don’t…

    If you edit an existing snippet that contains the percent sign and save it, the changes are not saved.

    Plugin Author Shea Bunge

    (@bungeshea)

    Oh, I see. Sorry for misunderstanding. I haven’t had the chance to test the plugin with your fix applied, but I will do so soon. I’m still miffed that this isn’t solved by esc_sql(), but anyway.

    Perhaps this could be the cause of this issue? If this is the cause of all of the odd saving behaviour, I owe you a big thank-you.

    Function esc_sql() use addslashes or mysql_real_escape_string, nothing more.

    Perhaps this could be the cause of this issue?

    I ‘m pretty sure, because google maps code contains the percent sign.

    Plugin Author Shea Bunge

    (@bungeshea)

    I’ve added your fix to the next version of Code Snippets, but I am thinking it might be best to find a more reliable method of preparing data for insertion into the database in a future version. Thanks for picking up the bug and finding a fix!

    I ended up using the following fix

    escape_snippet_data
    $snippet->code = str_replace( '%', '%%', $snippet->code );

    unescape_snippet_data
    $snippet->code = str_replace( '%%', '%', $snippet->code );

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Percent sign bug’ is closed to new replies.