escaping

Where is the proper place to escape quotes in Play Framework?

蹲街弑〆低调 提交于 2019-12-03 17:26:16
I have the following flow: A user is presented with a form. He fills in the form fields, and submits to the controller, which persists this to the DB On another page, the Controller gets this record from the DB, and passes it to the view The view captures it as a javascript variable: var foo = '${user.bar}'; Now, if the user enters this string in the form: I have a quote - ' - very dangerous then the quote is passed through all the way to the DB and back, and results in a corrupt javascript statement: var foo = 'I have a quote - ' - very dangerous'; What is the best place to escape this

Replacing newline character in javascript

早过忘川 提交于 2019-12-03 16:46:10
问题 I am trying to replaces instances of \r or \n characters in my json object with <br /> for display on a website. I tried: myString = myString.replace("\\r?\\n", "<br />"); But this doesn't seem to do anything. When I replace the regex with something else (like "a" for instance, the replace works as expected). Any ideas why this isn't working for the newline chars? 回答1: Try this: myString = myString.replace(/[\r\n]/g, "<br />"); Update : As told by Pointy on the comment below, this would

double quotes escaping in golang exec

六月ゝ 毕业季﹏ 提交于 2019-12-03 15:58:06
i need to run following command: ffmpeg -i input.jpg -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'" output_320x240_boxed.png so i execute: cmd = exec.Command("ffmpeg", "-i", "input.jpg", "-vf", "scale=\"'if(gt(a,4/3),640,-1)':'if(gt(a,4/3),-1,300)'\"", "output_320x240_boxed.png") it fails with following error: Error when evaluating the expression 'if(gt(a,4/3),-1,300)"'. Maybe the expression for out_w:'"if(gt(a,4/3),640,-1)' or for out_h:'if(gt(a,4/3),-1,300)"' is self-referencing. Command works when executed in command line. Why does it happen and how can i escape those double

Shellwords.shellescape implementation for Ruby 1.8

允我心安 提交于 2019-12-03 15:40:47
While the build of 1.8.7 I have seems to have a backported version of Shellwords::shellescape , I know that method is a 1.9 feature and definitely isn't supported in earlier versions of 1.8. Does anyone know where I can find, either in Gem form or just as a snippet, a robust standalone implementation of Bourne-shell command escaping for Ruby? You might as well just copy what you want from shellwords.rb in the trunk of Ruby's subversion repository (which is GPLv2 'd): def shellescape(str) # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? str = str.dup #

How can I escape special symbols in scala string?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 15:39:53
Is there a general Scala utility method that converts a string to a string literal? The simple lambda function "\"" + _ + "\"" only works for strings without any special characters. For example, the string \" (length 2) should be converted to the string "\\\"" (length 6). Have a look at Apache Common's StringEscapeUtils class ( docs here ). escapeJava should get the job done. Have a look at this example to see it in action (in Java). Wrap the String with 3 quotes to represent it as is.. e.g. val str = """ \" """ // str : java.lang.String = \" 来源: https://stackoverflow.com/questions/17341079

echo that shell-escapes arguments [duplicate]

狂风中的少年 提交于 2019-12-03 15:28:12
问题 This question already has answers here : Command to escape a string in bash (3 answers) Closed last year . Is there a command that not just echos it's argument but also escapes them if needed (e.g. if a argument contains white space or a special character)? I'd need it in some shell magic where instead of executing a command in one script I echo the command. This output gets piped to a python script that finally executes the commands in a more efficient manner (it loads the main() method of

escaping html inside comment tags

和自甴很熟 提交于 2019-12-03 15:24:38
escaping html is fine - it will remove < 's and > 's etc. ive run into a problem where i am outputting a filename inside a comment tag eg. <!-- ${filename} --> of course things can be bad if you dont escape, so it becomes: <!-- <c:out value="${filename}"/> --> the problem is that if the file has "--" in the name, all the html gets screwed, since youre not allowed to have <!-- -- --> . the standard html escape doesnt escape these dashes, and i was wondering if anyone is familiar with a simple / standard way to escape them. Definition of a HTML comment : A comment declaration starts with <!,

Rails escape_javascript creates invalid JSON by escaping single quotes

落花浮王杯 提交于 2019-12-03 15:15:43
问题 The escape_javascript method in ActionView escapes the apostrophe ' as backslash apostrophe \' , which gives errors when parsing as JSON. For example, the message "I'm here" is valid JSON when printed as: {"message": "I'm here"} But, <%= escape_javascript("I'm here") %> outputs "I\'m here" , resulting in invalid JSON: {"message": "I\'m here"} Is there a patch to fix this, or an alternate way to escape strings when printing to JSON? 回答1: Just call .to_json on a string and it will be escaped

What is the best escape character strategy for Python/MySQL combo?

a 夏天 提交于 2019-12-03 14:48:42
问题 This is my query. cursor2.execute("update myTable set `"+ str(row[1]) +"` = \"'" + str(row[3]) +"'\" where ID = '"+str(row[0])+"'") It is failing when row values have double quotes "some value". How do I escape all special characters? 回答1: Here is an example: import MySQLdb column = str(MySQLdb.escape_string(row[1])) query = "update myTable set %(column)s = %%s where ID = %%s" % dict(column = column) cursor2.execute(query, [row[3], row[0]]) Update Here is a brief commentary: column = str

When i need to escape Html string?

孤者浪人 提交于 2019-12-03 13:25:44
In my legacy project i can see the usage of escapeHtml before string is sent to browser. StringEscapeUtils.escapeHtml(stringBody); I know from api doc what escapeHtml does.here is the example given:- For example: "bread" & "butter" becomes: "bread" & "butter". My understanding is when we send the string after escaping html its the browser responsibility that converts back to original characters. Is that right? But i am not getting why and when it is required and what happens if we send the string body without escaping html? what is the cost if we dont do escapeHtml before sending it to browser