WordPress-Importer icon indicating copy to clipboard operation
WordPress-Importer copied to clipboard

Comment quotes slashed

Open smerriman opened this issue 8 years ago • 6 comments

After running the importer, all apostrophes and quotes in comments had visible slashes inserted beforehand.

smerriman avatar Mar 08 '17 02:03 smerriman

Very strange; we call wp_slash(), however this is immediately undone instead wp_insert_comment()...

Can you share your import file (or just a single comment from it)?

rmccue avatar Mar 08 '17 05:03 rmccue

(Also, is this for new comments, or comments being updated?)

rmccue avatar Mar 08 '17 05:03 rmccue

All comments. Calling wp_slash is incorrect - the line immediately before:

$comment = wp_filter_comment( $comment );

runs pre_comment_content, which has a default kses filter which adds slashes, thus the double escaping.

smerriman avatar Mar 08 '17 21:03 smerriman

Ah WordPress, you continue to disappoint me. This may be additionally stripping a layer of slashes in that case, if wp_filter_comment expects slashed data.

rmccue avatar Mar 08 '17 23:03 rmccue

I think you may have misunderstood - wp_filter_comment takes the raw data and does all the slashing for you already. So there's no need for wp_slash in the plugin - remove that, and everything works perfectly.

This replicates the core logic, which calls wp_filter_comment and passes the result to wp_insert_comment without an extra wp_slash.

smerriman avatar Mar 09 '17 00:03 smerriman

From memory, internally wp_filter_comment calls wp_kses_filter, which runs addslashes( wp_kses( stripslashes( $data ) ) ), so my guess is that we need to add slashes before wp_filter_comment, and then not add them later. (Again, this is from memory, I'll check when I'm at my desk.)

The existing importer potentially has this bug too: https://core.trac.wordpress.org/ticket/35839

rmccue avatar Mar 09 '17 00:03 rmccue