WordPress.org

Ready to get started?Download WordPress

Forums

Code Snippets
[resolved] Percent sign bug (9 posts)

  1. nikan06
    Member
    Posted 11 months ago #

    Fisrt i would like to say that this plugin is a must for wordpress and not only. Thanks for creating it Shea.

    Editing code snippet with percent sign in code, like in stylesheet top: 20%; the changes i make doesnt saved.

    http://wordpress.org/plugins/code-snippets/

  2. nikan06
    Member
    Posted 11 months ago #

    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 );

  3. Shea Bunge
    Member
    Plugin Author

    Posted 11 months ago #

    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.

  4. Shea Bunge
    Member
    Plugin Author

    Posted 11 months ago #

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

  5. nikan06
    Member
    Posted 11 months ago #

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

  6. Shea Bunge
    Member
    Plugin Author

    Posted 11 months ago #

    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.

  7. nikan06
    Member
    Posted 11 months ago #

    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.

  8. Shea Bunge
    Member
    Plugin Author

    Posted 10 months ago #

    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!

  9. nikan06
    Member
    Posted 10 months ago #

    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 );

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.