stevebauman/purify

Purify replaces \n with \r\n

Closed this issue · 3 comments

Hi There,

I'm currently using Purify in my Laravel form validations.

Essentially I clean an input string and compare it to the original and if they are not identical then something illegal was entered into the field and the user is asked to correct their input.

However, I've noticed that textarea fields that contain \n newlines are replaced in Purify by \n\r and therefore cleaned content does not match original content and user is asked to remove illegal markup.

Is there a way to bypass this please?

Thanks

Hi @benwrigley,

I think Output.Newline is the configuration option you're looking for here:

http://htmlpurifier.org/live/configdoc/plain.html#AutoFormat.RemoveEmpty.RemoveNbsp#Output.Newline

Newline string to format final output with. If left null, HTML Purifier will auto-detect the default newline type of the system and use that; you can manually override it here. Remember, \r\n is Windows, \r is Mac, and \n is Unix.

Add this option into your configuration, clear your cache (by running php artisan cache:clear) and then try again:

// config/purify.php

'settings' => [

    // ....

    'Output.Newline' => '\n',

Let me know if you still have issues!

Hi @stevebauman,

I do apologise, I think it must be pure laziness that has led me not to find that! Please forgive me.

And thank you for such a great tool.

Best wishes.

No problem at all @benwrigley! Thanks so much for your kind words 😄