escaping

filter_var vs htmlentities vs htmlspecialchars

喜夏-厌秋 提交于 2019-12-01 02:41:23
Disclaimer This is not a question about whether we should be escaping for database input. This is strictly looking at the technical differences between the three functions in the title. There is this question discussing the difference between htmlentities() and htmlspecialchars() . But, it doesn't really discuss filter_var() and the information I found on Google was more along the lines of "Make sure you escape user input before it is echo'd!" My questions are: Why are htmlspecialchars() and htmlentities() commonly used over filter_var() ? Is there some performance hit from using filter_var()

Unescaping Characters in a String with Python

纵饮孤独 提交于 2019-12-01 02:05:10
问题 I made a JSON request that gives me a string that uses Unicode character codes that looks like: s = "\u003Cp\u003E" And I want to convert it to: s = "<p>" What's the best way to do this in Python? Note, this is the same question as this one, only in Python except Ruby. I am also using the Posterous API. 回答1: If the data came from JSON, the json module should already have decoded these escapes for you: >>> import json >>> json.loads('"\u003Cp\u003E"') u'<p>' 回答2: >>> "\\u003Cp\\u003E".decode(

How to properly escape quotes in powershell v2?

扶醉桌前 提交于 2019-12-01 02:01:05
How do you properly escape quotes in powershell v2 (called from within a batch file)? I have tried: powershell -Command "(gc file1.txt) -join "`n" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join ""`n"" | Out-File file2.txt" and powershell -Command "(gc file1.txt) -join '"`n`" | Out-File file2.txt" but they all fail. Editor's note : The purpose of the command is to transform Windows CRLF line breaks to Unix LF-only ones, so as to create a file that will be processed on Linux. From a batch file ( cmd.exe ), you must \ -escape embedded " instances (even though PowerShell-

How to escape “:” in Oracle dynamic SQL and also have bind variables?

橙三吉。 提交于 2019-12-01 01:43:04
问题 I'm trying to make the following a dynamic SQL, but : character is messing up - alter session set events 'sql_trace [sql: asasasaass]'; Example: declare l_trc_cmd varchar2(500); l_sql_id varchar2(500) := 'asasasaass'; begin l_trc_cmd := q'# alter session set events 'sql_trace [sql: :L_SQL_ID]' #'; execute immediate l_trc_cmd using l_sql_id; end; / Above fails with: ERROR at line 1: ORA-01006: bind variable does not exist One : is required as per syntax of the SQL, and another : is for bind

Decode HTML escaped characters back to normal string in C#

不羁岁月 提交于 2019-12-01 01:19:03
问题 My question is simple. I searched a little online, but could not find a quick way to unescape HTML text in a string. For example: "< > &" should be returned to "< > &" as a string. Is there a quick way, or do I have to write my own unescaper? 回答1: use System.Web.HttpUtility.HtmlDecode or System.Net.WebUtility.HtmlDecode var decoded = HttpUtility.HtmlDecode("< > &"); 回答2: If you're using .NET 4.5 then you can use the HttpUtility.HtmlDecode method. 回答3: HttpUtility.UrlDecode("Your escaped

Preserving escapes in bash arguments $@

﹥>﹥吖頭↗ 提交于 2019-12-01 01:16:38
related to this: Preserve Quotes in bash arguments A simple example, where I simply run a command with nohup ... #!/bin/bash nohup "$@" ... ./myscript gedit some\ file\ with\ spaces.txt This works fine. However, I have no idea how to keep the correct bits of the arguments escaped when using an intermediate variable... #!/bin/bash CMD="$@" printf "%q\n" "$CMD" #for debugging nohup $CMD I've tried a few permutations and nothing works in all cases. What am I missing? Ideally I would like to be able to modify $CMD before nohup . You need to use an array. cmd=( "$@" ) printf '%q\n' "${cmd[@]}"

java resultset.getstring(“col_name”) query

雨燕双飞 提交于 2019-12-01 00:43:58
I have a simple query regarding ResultSet.getString() method in java for JDBC. Suppose the value in the Database column is having a \ which is javas escape character e.g. \n or \t etc. When i retrieve the value as getString() i see one more escape character is getting added and the actual meaning of this \n is now a string literal only. So i had to unescape java and then use it properly. String s= rs.getString("col_name"); When s contains `\n': System.out.println(s) output: \n After unescaping java using apache common StringEscapeUtils output: System.out.println("hi"+s+"hello"); hi hello My

In Django, How do I get escaped html in HttpResponse?

人走茶凉 提交于 2019-11-30 23:52:35
问题 The following code in one of my views returns unescaped html string which cannot be parsed in frontend since it is an Ajax request. return render_to_response(template_name, { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, }, context_instance=RequestContext(request)) What is the simplest way to correct this ? Thanks in advance.. 回答1: Lakshman Prasad 's answer is technically correct, but a bit cumbersome. A better way to escape text would

Objective-C - How to convert NSString to escaped JSON string?

穿精又带淫゛_ 提交于 2019-11-30 22:55:03
I have a NSString that may contain quotes,\, /, \r, \n, and I want to convert it to a JSON encoded string so strings like this "text1\text2" becomes \"text1\\text2\" Is there a existing function to let me do this? Also, I am using SBJson in my project but I cannot find whether SBJson can do this or not. NSJSONSerialization is not on the table since my application still needs to support OSX 10.6 Does this answer your question? -(NSString *)JSONString:(NSString *)aString { NSMutableString *s = [NSMutableString stringWithString:aString]; [s replaceOccurrencesOfString:@"\"" withString:@"\\\""

Does C support raw string literals?

烂漫一生 提交于 2019-11-30 22:53:17
问题 C++11 added support for raw string literals, such as: R"foo(A " weird \" string)foo" Does C have such a thing? If so, in what version of the standard? C11? If not, does anyone know if it is being planed and if any compilers support it? 回答1: Does C have such a thing? If so, in what version of the standard? C11? C (C90, C99, C11) does not support this feature or any other similar feature. If not, does anyone know if it is being planed I have no idea, but usually there is a strong resistance of