escaping

Jinja2 escape all HTML but img, b, etc

这一生的挚爱 提交于 2019-12-02 19:26:34
Jinja2 automatically escapes all HTML tags, but I want to not escape some tags (like img , b , and some others). How can I do it? Alex Morega You can write your own filter. The scrubber library is pretty good at cleaning up HTML. The filter will need to wrap the returned string in jinja2.Markup so the template will not re-escape it. Edit: a code example import jinja2 import scrubber def sanitize_html(text): return jinja2.Markup(scrubber.Scrubber().scrub(text)) jinja_env.filters['sanitize_html'] = sanitize_html Sean Vieira You'll want to parse the input on submission using a white list approach

JPA/Hibernate: Escaping HQL keywords

江枫思渺然 提交于 2019-12-02 19:17:00
问题 This is similar to How to escape reserved words in Hibernate's HQL. But I use JPA, so the solution isn't applicable. So, how can I escape HQL keywords in JPA? Example query: ( count is the offending.) em.createQuery("INSERT INTO Count (id, count) SELECT 1, ?").setParameter(1, id).executeUpdate(); There's this jira HHH-3811, still open. Not sure if relevant since it's about SQL keywords, not HQL keywords. 回答1: You could try something like this: em.createQuery("INSERT INTO Count c (c.id, c

Use of apostrophe (single-quote) in a Git commit message via command line [duplicate]

荒凉一梦 提交于 2019-12-02 18:41:53
This question already has an answer here: How to escape single quotes within single quoted strings 21 answers I am trying to take this one step further. How could this work in a standard Bash shell? git commit -m 'cracked enigma's code' Could this simply be done with backslash-escaping like the following? git commit -m 'cracked enigma\'s code' Further, how could double-quotes be used? Also by backslash-escaping? Would that be the best way? Are there any good alternative ways? git commit -m 'cracked the "real" enigma's code' Use double quotes: git commit -m "cracked enigma's code" Or, if your

How to replace/escape U+2028 or U+2029 characters in PHP to stop my JSONP API breaking

﹥>﹥吖頭↗ 提交于 2019-12-02 18:14:27
Ok I am running a public JSONP API which the data is served from my PHP server. I just read this article: JSON: The JavaScript subset that isn't (by Magnus Holm; May 2011) (please read for clarification) Basically if my JSON strings contains a U+2028 character (Unicode line separator) or U+2029 character (Unicode paragraph separator) then this is perfectly valid JSON. However when using JSONP the JSON gets executed as JavaScript and no string in JavaScript can contain a literal U+2028 or a U+2029 as it will break the JavaScript. Apparently this is usually not a problem as long as you use a

split a string at comma but avoid escaped comma and backslash

为君一笑 提交于 2019-12-02 18:06:50
问题 I'd like to split a string at comma "," . The string contains escaped commas "\," and escaped backslashs "\\" . Commas at the beginning and end as well as several commas in a row should lead to empty strings. So ",,\,\\,," should become "" , "" , "\,\\" , "" , "" Note that my example strings show backslash as single "\" . Java strings would have them doubled. I tried with several packages but had no success. My last idea would be to write my own parser. 回答1: In this case a custom function

Replace all occurences of char inside quotes on PHP

女生的网名这么多〃 提交于 2019-12-02 18:02:50
问题 How could I convert something like this: "hi (text here) and (other text)" come (again) To this: "hi \(text here\) and \(other text\)" come (again) Basically, I want to escape "only" the parentheses that are inside quotes. EDIT I'm to new in Regex and so, I tried this: $params = preg_replace('/(\'[^\(]*)[\(]+/', '$1\\\($2', $string); But this will just escape the first occurrence of (. EDIT 2 Maybe I should mention that my string could have these parentheses already escaped and, in this case,

Python escaping backslash

会有一股神秘感。 提交于 2019-12-02 17:59:16
问题 I'm trying to escape the backslash, but trying to understand the right way of doing it foo = r'C:\Users\test.doc' The above works fine However, when I want to escape the path stored in a variable For example : parser.add_argument('-s', '--source', type = str, help = 'Source file path') Now, how do escape the value in - args.source 回答1: So there are a few escape sequences to be aware of in python and they are mainly these. So when the string for that file location is parsed by the add_argument

Overwrite last line on terminal

独自空忆成欢 提交于 2019-12-02 16:32:00
My bash-script looks as following: echo "Description:" while [ $finishInput -eq 0 ]; do read tmp desc="$desc"$'\n'"$tmp" if [ -z "$tmp" ]; then finishInput="1" fi done echo -n "Maintainer:" read maintainer It reads to the desc var until a empty line is passed. After that, i want to read in other stuff. When executing my current script it looks like this: Description: Line 1 Line 2 Maintainer: I would like to overwrite the last empty line with the "Maintainer:". I searched for a solution but only found suggestions which were like echo -n "Old line" echo -e "\r new line" which stays on the line

How to use SED to find and replace URL strings with the “/” character in the targeted strings? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-02 16:09:40
This question already has an answer here: Trying to escape a / for sed on ubuntu 4 answers I'm attempting to use SED through OS X Terminal to perform a find and replace. Imagine I have this string littered throughout the text file: http://www.find.com/page And I want to replace it with this string: http://www.replace.com/page I'm having trouble because I'm not sure how to properly escape or use the "/" character in my strings. For example if I simply wanted to find "cat" and replace with "dog" I've found the following command that works perfectly: sed -i '' 's/cat/dog/g' file.txt Does anyone

Java replace issues with ' (apostrophe/single quote) and \\ (backslash) together

橙三吉。 提交于 2019-12-02 15:52:51
I seem to be having issues. I have a query string that has values that can contain single quotes. This will break the query string. So I was trying to do a replace to change ' to \' . Here is a sample code: "This is' it".replace("'", "\'"); The output for this is still: "This is' it". It thinks I am just doing an escape character for the quote. So I tried these two pieces of code: "This is' it".replace("'", "\\'"); // \\ for the backslash, and a ' char "This is' it".replace("'", "\\\'"); // \\ for the backslash, and \' for the ' char Both of the above STILL results in the same output: "This is