escaping

Allowing <br> tags with Google App Engine and Jinja2

社会主义新天地 提交于 2019-11-30 19:42:43
In my web app, the user can make blog posts. When I display the blog post, newlines aren't shown because I didn't replace the new lines with <br> tags. The problem is that I've turned autoescaping on in Jinja, so <br> tags are escaped. I don't want to temporarily disable autoescaping, I want to specifically allow <br> tags. How would I do this? I have another answer that I think is the best. Initially I was just displaying my variable post.content as-is, and the newlines weren't being preserved. None of the solutions here worked (well), and my pre solution was just a quick fix and had major

escaping backslash in java string literal [duplicate]

怎甘沉沦 提交于 2019-11-30 19:33:54
This question already has an answer here: Replacing single '\' with '\\' in Java 6 answers I am using Java for a while and come up with this problem: I use hard-coded paths in windows like "D:\Java-code\JavaProjects\workspace\eypros\src" The problem is that I need to escape the backslash character in order to use it with string. So I manually escape each backslash: "D:\\Java-code\\JavaProjects\\workspace\\eypros\\src" Is there a way to automatically take the unescaped path and return an escaped java string. I am thinking that maybe another container besides java string could do the trick (but

Preserving escapes in bash arguments $@

南笙酒味 提交于 2019-11-30 19:27:03
问题 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

Regular expression to match escaped characters (quotes)

雨燕双飞 提交于 2019-11-30 19:06:08
I want to build a simple regex that covers quoted strings, including any escaped quotes within them. For instance, "This is valid" "This is \" also \" valid" Obviously, something like "([^"]*)" does not work, because it matches up to the first escaped quote. What is the correct version? I suppose the answer would be the same for other escaped characters (by just replacing the respective character). By the way, I am aware of the "catch-all" regex "(.*?)" but I try to avoid it whenever possible, because, not surprisingly, it runs somewhat slower than a more specific one. The problem with all the

Django. PostgreSQL. regexp_split_to_table not working

拟墨画扇 提交于 2019-11-30 18:59:20
问题 I am trying to tokenize my table fields with a query. SELECT regexp_split_to_table(mytable.field_name, E'\\s+') from mytable limit 20; This works when I execute it from psql shell but when I do: from django.db import connection cursor=connection.cursor() cursor.execute("SELECT regexp_split_to_table(mytable.field_name,E'\\s+') FROM mytable LIMIT 20") cursor.fetchall() ... it fails to return tokens. What am I doing wrong? 回答1: The backslash is treated as meta-character by Django and is

Swift UITesting error: Invalid escape sequence in literal. \\U201c

你。 提交于 2019-11-30 18:54:49
I am building an automation suite using Xcode 7 with swift. My app loads with the following Alert View: Allow "Light Alarm" to access your location while you use the app? When I record with UI Testing and click this alert I get the following code: app.alerts["Allow \U201cLight Alarm\U201c to access your location while you use the app?"] Note: The quotes has been replaced with \U201c However, when I try and compile I get the following error: "Invalid escape sequence in literal" Anyone know how to get round this? Martin R This seems to be a bug in Xcode when generating code during UI recording.

Python version of PHP's stripslashes

与世无争的帅哥 提交于 2019-11-30 18:45:34
I wrote a piece of code to convert PHP's striplashes into valid Python [backslash] escapes: cleaned = stringwithslashes cleaned = cleaned.replace('\\n', '\n') cleaned = cleaned.replace('\\r', '\n') cleaned = cleaned.replace('\\', '') How can I condense it? Not totally sure this is what you want, but.. cleaned = stringwithslashes.decode('string_escape') It sounds like what you want could be reasonably efficiently handled through regular expressions: import re def stripslashes(s): r = re.sub(r"\\(n|r)", "\n", s) r = re.sub(r"\\", "", r) return r cleaned = stripslashes(stringwithslashes) You can

How can escaping be used to prevent XSS attacks?

半世苍凉 提交于 2019-11-30 18:11:41
问题 To prevent XSS attacks, output escaping has been enabled; The above is from symfony,but I don't understand. 回答1: XSS is an abbreviation for "Cross-site scripting". Cross-site scripting attacks occur when you manage to sneak a script (usually javascript) onto someone else's website, where it can run maliciously. XSS is possible when you have user input into a web site. For instance, if I was filling out a web form, and it asked me for my name, I could enter My name is <script src="http://bad

AngularJS - Render HTML tags that are contained in a string

不问归期 提交于 2019-11-30 18:02:15
My database stores product information, and a lot of this is organised into lists. I load the data into Angular as $scope.post . For instance, $scope.post.size_description = '<li> Fits true to size. Take your normal size\r</li> <li> Slim-cut, mid-rise style</li> <li> Long in length, alter to fit</li> <li> Model wears an IT 48\r</li> <li> Model measures: waist size 32, height 6\'1"/ 185cm\r</li>'. When I try to load this data into my Angular app, it gets rendered as text (i.e. the <li> are not parsed). I understand this probably happens for security reasons, but is there any way around it? jzm

Convering double backslash to single backslash in Python 3

我与影子孤独终老i 提交于 2019-11-30 17:41:42
问题 I have a string like so: >>> t '\\u0048\\u0065\\u006c\\u006c\\u006f\\u0020\\u20ac\\u0020\\u00b0' That I made using a function that converts unicode to the representative Python escape sequences. Then, when I want to convert it back, I can't get rid of the double backslash so that it is interpreted as unicode again. How can this be done? >>> t = unicode_encode(" >>> t '\\u0048\\u0065\\u006c\\u006c\\u006f\\u0020\\u20ac\\u0020\\u00b0' >>> print(t) \u0048\u0065\u006c\u006c\u006f\u0020\u20ac\u0020