In the Settings of CSV file format it is already possible to replace newlines in rendered fields.

But with this option you can only replace "real" line feeds (\n). Because in Windows it is normal that a linefeed consists of a Carriage Return plus a Linefeed (\r\n) it would be nice if you could choose what to replace.

Please find attached a patch (against the last dev-version) to enhance the functionality accordingly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TWD’s picture

Has this been committed to 7.x-3.0-beta6 ?

I am still having this issue.

Steven Jones’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This needs some tests to make sure that the patch does what it should, and the patch in the OP was also diffed in the wrong direction, i.e. you have to apply the reverse to get it to apply.

nemethf’s picture

I made a patch based on smitty's one. It replaces all the new line combinations ('\r\n' or '\n' or '\n') by choosing the second option on the style settings. It is needed for us, because text field values in our db are inhomogeneous regarding the new lines. Test cases are included.

nemethf’s picture

Status: Needs work » Needs review
arnested’s picture

Status: Needs review » Needs work

You need change all the strings containing \n, \r\n, and \r to use double quotes instead of single quotes.

Otherwise you'll just replace literal occurrences of \n, \r\n, and \r. That is why the tests also succeed.

Change that and I'll be ready to RTBC :-)

arnested’s picture

Status: Needs work » Needs review
FileSize
6.32 KB

I made the changes mentioned in #5.

Status: Needs review » Needs work

The last submitted patch, 6: views_data_export-allow_carriage_return-1957114-6.patch, failed testing.

arnested’s picture

Status: Needs work » Needs review
FileSize
6.33 KB

Ooops. The test case wasn't fixed correctly.

New patch added.

arnested’s picture

Title: Allow Carriage Rerturn to be replaced » Allow Carriage Return to be replaced
nemethf’s picture

Thanks Arne, for pointing to the quotation bug. I tested the corrected patch. Works well with test data.

ikeigenwijs’s picture

Status: Needs review » Reviewed & tested by the community

Patch applied directly.
Works as advertised this was exactly what we needed.

We have mixed environments Windows and Linux so \n and \n\r are used.

  • Steven Jones committed 9b840da on 7.x-3.x
    Issue #1957114 by arnested, nemethf, smitty, ikeigenwijs: Added allow...
Steven Jones’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

Thanks everyone for the patch and the work, fixed in 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

vasike’s picture

it seems the replacement doesn't work properly for special characters: as \n

For example there could be both Carriage Return plus Linefeed ("\r\n") and single Linefeed ("\n") that we want to replace with single Linefeed ("\n")

With the current code we'll get the '\n' string instead of single Linefeed ("\n")

Here is patch that could help for this kind of replacements.