WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Code Editor
Restoring a commit does not work properly. (7 posts)

  1. invot
    Member
    Posted 10 months ago #

    When I commit a version of a file and then try to return it, my file is filled with an 'n' where my line breaks should be.

    http://wordpress.org/plugins/advanced-code-editor/

  2. adriangreen
    Member
    Posted 10 months ago #

    I can confirm this in version 2.2.5.
    Clearly an escaping issue...

    <?phpn/**n * ...

    The malformed html is present in the database table filemeta so it's getting mangled on "commit".

  3. adriangreen
    Member
    Posted 10 months ago #

    Problem isolated:
    the problem is that on commit the code calls func
    add_file_meta which then calls built-in func
    add_metadata
    - this function uses func wp_unslash on the passed in value.

    wp_unslash removes escape slashes like in
    O\'Brian >> O'Brian

    So our poor newlines are being converted to "n"

    2 newlines next \n\nNewline here >> newline next nnNewline here

  4. adriangreen
    Member
    Posted 10 months ago #

    ...aaaanyway

    the simple fix for this is to not use esc_sql in function ajax_commit_file as subsequent call to add_metadata sanitizes input anyhow, it's a bit redundant:

    $file_content = /**esc_sql**/($_POST['file_content']);

  5. widecast
    Member
    Posted 6 months ago #

    Adrian, thanks for the fix. I would have never figured that out myself. Working properly now!

  6. widecast
    Member
    Posted 5 months ago #

    @Adrian, I just restored a theme file that had strings with escaped characters. Upon restoration, the file was messed up due to my escaped characters getting unescaped... I know you mentioned "wp_unslash" earlier which must be the culprit.

    In your opinion, is this normal behavior? How can this be avoided?

  7. adriangreen
    Member
    Posted 5 months ago #

    It can easily be avoided, but I don't think the author cares. The plugin is clearly incomplete in it's realization. I stopped using it. Idea: The data could be stored using base64_encode/decode to avoid all these issues.
    You're best going to the author for a proper fix...

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.