WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 months ago

#22279 new defect (bug)

WordPress Export/Import deletes carriage returns

Reported by: mykle Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 3.4.2
Component: Export Keywords:
Focuses: Cc:

Description (last modified by ocean90)

WordPress export does not translate or escape bare CR characters in a CR/LF pair. They show up unfiltered in the WXR export file. I see this both in post_content and in strings that were serialized into a post_meta field. The CR characters are in the WXR file, unfiltered.

Then, WordPress import loses these CR characters. They are simply erased. It may be because SimpleXMLParser can't or won't open the XML file in binary mode, so line ending translation can & does happen. That's just a theory, but if it's true then this behavior might *not* happen on all platforms or with all PHP versions. (I'm seeing this on OS X 10.6.8, PHP 5.4.4.)

In the worse case -- mine -- the munged string is a small component of a complex datastructure that is serialized in a postmeta record. In this case, the entire meta_value field is deleted on import, because the data won't unserialize, because its length has changed.

It seems to me that WP Export should escape any character that might be threatened in transit. I'm no XML lawyer, but some sources claim that unescaped CR characters are invalid XML.

To reproduce:

  • store a carriage return in a post.
  • export it to a WXR file.
  • examine the WXR file for the raw carriage return (^M).
  • import that file.
  • search for the carriage return.

Change History (3)

comment:1 @ocean9014 months ago

  • Description modified (diff)
  • Summary changed from Wordpress Export/Import deletes carriage returns to WordPress Export/Import deletes carriage returns

comment:2 @WraithKenny10 months ago

I've had issues with this, and couldn't figure out the proper solution.

Support forum issues are usually resolved (or abandoned) with vague explanations that plugins are doing it wrong. As a plugin developer that IS doing this wrong, it's really not helpful since it's extremely hard to figure out what I'm actually doing wrong, since there exists no good explanation of the problem, nor any best practice tutorial for doing it right (what ever that may be). The only thing I do know about this issue is that sometimes the length of serialized meta is wrong do to line-endings. (Why the line-endings are sometimes CR/LF I haven't been able to trace, but think it's do to ajax saves, in my plugin at least.)

My feeling is, if you are using the correct APIs and sanitation practices, something like this shouldn't happen: there should be no extra unknown step for plugin developers to do (like say normalize all line-endings prior to update_option/_post_meta? No idea if that'd work, and that's the point: There's no community education around this issue). I'm sure the majority of authors have no idea if the exporter/importer works with their meta.

Anyway, if this is a plugin developer problem, some guidance would be appreciated, if not, a bug fix would be appreciated.

comment:3 @GaryJ8 months ago

The WPTest.io export naturally suffers from the same problem. One can't just edit the .xml file, since saving it results in the mix of line endings (XML vs content) all trying to be the same, which may then cause problems for importing.

Note: See TracTickets for help on using tickets.