How to preserve new line \n with laravel sanitizer - laravel

I'm trying to store text in my database with \n, so that there can be new lines whenever the admin wants. The problem I am getting is that automatically it seems laravel is sanitizing all strings that get saved to the DB. So it's saving it as \n. And then when I retrieve it (i retrieve and display with vue components not a blade file), it doesn't format it as a new line. how and what am i supposed to do. what is the right way of achieving being able to save a paragraph with new lines made with \n?

I think you need to convert the \n to be. you can do something like this:
<?php
echo nl2br("foo isn't\n bar");
?>

Related

how to remove WhiteSpaces in telegram instant view API?

I am trying to setup a Telegram Instant View for a website.
this website has a lot of empty tags that i don't know how to remove them.
<p style="text-align: justify;"> </p>
i want to find a way to remove and get rid of these kind of tags
If you want to remove just use #replace function:
#replace("\u00a0", ""): //nodes/text()
If you want to remove tags with spaces, call #remove and pass a predicate, that selects empty nodes after space normalization.
#remove: //nodes[not( normalize-space(text()) )]
I found it Ehasn:
First replace all " " content with sample string like "null-tag" the remove them using this code:
#replace("\u00a0", "null-tag"): //p
#remove: //p[.="null-tag"]
Note that it might change some contents check some pages to make sure it work fine for you.

Processing form input in a Joomla component

I am creating a Joomla component and one of the pages contains a form with a text input for an email address.
When a < character is typed in the input field, that character and everything after is not showing up in the input.
I tried $_POST['field'] and JFactory::getApplication()->input->getCmd('field')
I also tried alternatives for getCmd like getVar, getString, etc. but no success.
E.g. John Doe <j.doe#mail.com> returns only John Doe.
When the < is left out, like John Doe j.doe#mail.com> the value is coming in correctly.
What can I do to also have the < character in the posted variable?
BTW. I had to use & lt; in this question to display it as I want it. This form suffers from the same problem!!
You actually need to set the filtering that you want when you grab the input. Otherwise, you will get some heavy filtering. (Typically, I will also lose # symbols.)
Replace this line:
JFactory::getApplication()->input->getCmd('field');
with this line:
JFactory::getApplication()->input->getRaw('field');
The name after the get part of the function is the filtering that you will use. Cmd strips everything but alphanumeric characters and ., -, and _. String will run through the html clean tags feature of joomla and depending on your settings will clean out <>. (That usually doesn't happen for me, but my settings are generally pretty open to the point of no filtering on super admins and such.
getRaw should definitely work, but note that there is no filtering at all, which can open security holes in your application.
The default text filter trims html from the input for your field. You should set the property
filter="raw"
in your form's manifest (xml) file, and then use getRaw() to retrieve the value. getCmd removes the non-alphanumeric characters.

json and line break

I hope, there is a solving of my question. But I can't find it.
Problem: ajax return data with line break (\n). The data must be insert into textarea and will be update from ajax.
I can replace '\n' when reading data (myJsonData.replace.() ... etc). The main problem: how to ready data for textarea to display in correct format with line break?
just replace it to something revertable, like -=br=- and when insert to the textarea, replace back to \n
There is no problem with line breaks in textarea and you just can insert the data as is. But if you still have problems with special chars - you can encode your JSON data and decode it on insert.

How do I replace carriage returns with <br /> using freemarker and spring?

I've got an internationalised app that uses spring and freemarker. I'm getting content from localised property files using.
${rc.getMessage("help.headings.frequently_asked_questions")}
For some of the content there are carriage returns in the property values. Because I'm displaying in a web page I'd like to replace these with .
What is the best way to do this?
Edit: looking closer it seems that I don't actually have carriage returns in the property files. The properties are coming back as single line strings.
Is there a better way to declare the properties so they know they are multi-line?
help.faq.answer.new_users=If you have not yet set a PIN, please enter your username and passcode (from your token) in the boxes provided and leave the PIN field blank.\
You will be taken through the steps to create a PIN the first time you log in.
Cheers,
Pete
${springMacroRequestContext.getMessage("help.headings.frequently_asked_questions", [], "", false)?html?replace("\n", "<br>")}
To handle CR + LF (carriage return + line feed) line endings, as well as just LF do this:
<#escape x as x?html?replace("\\r?\\n","<br />",'r')>...</#escape>
<#escape x as x?html?replace('\n', '<br>')>...</#escape>
works just fine.
If you want this to be the default behaviour, consider writing a custom TemplateLoader as suggested in this blog: http://watchitlater.com/blog/2011/10/default-html-escape-using-freemarker/.
As to the
Is there a better way to declare the properties so they know they are multi-line?
part of your question, maybe this helps: you can include line terminator characters in your property values by using the \r and \n escape sequences, like it is explained in the API documentation of java.util.Properties#load(java.io.Reader).
I would recommend writing a custom directive for it (see freemarker.template.TemplateDirectiveModel), so in your templates you can write something like <#my.textAsHtml springMacroRequestContext.getMessage(...) />. It's important that this is a directive, not function, so it works properly inside <#escape x as x?html>...</#escape>. Otherwise it would be double-escaped. Using a directive can also give the highest performance, as you can directly send the output to the output Writer, rather than building a String first.

removing <br/> from GET request

I'm using a get request to get some page data but need to strip the break tags from the finished file. Basically what I'm doing is taking the output of the get request and saving it to a file but it has hundereds of break tags in it I need removed. I'm fine with running a batch or vb script after the file is saved to remove the tags but I'm not sure how on how to do that either. So far the only solutions I have seen is to remove entire lines.
EDIT: This will be deployed to multiple Windows servers so I would like to keep the requirements as minimal as possible. I.E. commands/software that Windows has by default.
If you're au fait with Python, you could use Beautiful Soup to remove <br /> elements in a fairly robust manner. See here for how to remove elements from the tree.
Unless I have misunderstood you could replace the break tags using the replace function in vbscript (assumed from the tag). For example:
cleanedText = Replace(rawText,"<br/>",""))
More information on usage can be found here
http://www.w3schools.com/Vbscript/func_replace.asp
It is worth mention though that that function acts verbatim so you might have to run through a few times to get all common tag markup:
cleanedText = Replace(rawText,"<br/>","")) //no spaces
cleanedText = Replace(cleanedText,"<br />","")) // a space
cleanedText = Replace(cleanedText,"<br>","")) // unterminated

Resources