Title: Percent sign bug
Last modified: August 21, 2016

---

# Percent sign bug

 *  Resolved [nikan06](https://wordpress.org/support/users/nikan06/)
 * (@nikan06)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/)
 * 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/](http://wordpress.org/plugins/code-snippets/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [nikan06](https://wordpress.org/support/users/nikan06/)
 * (@nikan06)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019779)
 * 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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019780)
 * 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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019785)
 * Just tried creating a snippet that contains the `%` character, and it saves fine.
   Strange that your recieve this error and I don’t…
 *  Thread Starter [nikan06](https://wordpress.org/support/users/nikan06/)
 * (@nikan06)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019786)
 * If you edit an existing snippet that contains the percent sign and save it, the
   changes are not saved.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019787)
 * 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](http://wordpress.org/support/topic/weird-behavior-old-revisions-related?replies=2)?
   If this is the cause of all of the odd saving behaviour, I owe you a big thank-
   you.
 *  Thread Starter [nikan06](https://wordpress.org/support/users/nikan06/)
 * (@nikan06)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019799)
 * 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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019952)
 * 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!
 *  Thread Starter [nikan06](https://wordpress.org/support/users/nikan06/)
 * (@nikan06)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019953)
 * 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.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [nikan06](https://wordpress.org/support/users/nikan06/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/percent-sign-bug/#post-4019953)
 * Status: resolved