escaping

how to escape input but save unescaped into the database

心已入冬 提交于 2019-12-06 08:41:14
问题 It is said that in order to prevent from SQL injection one should filter the input data eg. with addslashes or mysql_real_escape_string depending on used connection modules However, data escaped with addslashes is being saved into the database WITH the slashes, so a user surname would save as O\'Reilly instead O'Reilly. The one needs to use stripslashes to display it correctly. So how do I use addslashes and save into the database without slashes? Is it actually the way it should be done? 回答1

Single quoted string vs. double quoted string

最后都变了- 提交于 2019-12-06 08:04:38
问题 Why do we need an escape character for single quoted string, but not for a double quoted string? a = 'hello how\'s it going' a1 = 'hello how's it going' b = "hello how's it going" assert(a==b) # Passes assert(a1==b) # Errors The error message: File "string.py", line 1 a = 'hello how's it going' ^ SyntaxError: invalid syntax 回答1: It doesn't matter if you use ' or " around the string to mark it as string literal. But you can't use that character inside the string literal without escaping it

Python Subprocess to delete reg key on Windows

本秂侑毒 提交于 2019-12-06 07:40:10
My code doesn't work as expected : import subprocess key = 'reg delete HKEY_USERS\S-1-5-21-2637495828-1099793317-3825703309-1000\SOFTWARE\Classes\CLSID\{0E270DAA-1BE6-48F2-AC49-D955BE4EEF1D} /f' subprocess.call(key, shell=True) Running Windows 10 64b, tried with subprocess.Popen aswell. My first thought is I have to escape \ somehow, but I'm not sure if that's what I need, nor how to do it. I also tried to make it work with a list of args key = ['reg', 'delete', 'HKEY...']) , which gave the same result Result from python script C:\test.py Error : Couldn't find the key or registry value Result

Escape table name in SQLite?

大憨熊 提交于 2019-12-06 07:23:40
I have table named References in SQLite, so I can't target it, it seems. SQLite studio I use to edit databases throws an error. Is there a way to escape database name? The query is: UPDATE References SET DateTimeLastEdited = datetime('now', 'localtime') WHERE NewsItemID = old.NewsItemID; (This is part of the trigger I am making.) You can escape table names with double quotes: UPDATE "References" SET DateTimeLastEdited = datetime('now', 'localtime') WHERE NewsItemID = old.NewsItemID; Depending on what you want to escape, you need to use different delimiters: If you want to use a keyword as a

How Do You Prevent A javax Transformer From Escaping Whitespace?

走远了吗. 提交于 2019-12-06 07:04:01
I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory = TransformerFactory.newInstance(); StreamSource source = new StreamSource(TRANSFORMER_PATH); Transformer transformer = factory.newTransformer(source); StringWriter extractionWriter = new StringWriter(); String xml = FileUtils.readFileToString(new File(sampleXmlPath)); transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(extractionWriter)); System.err.println(extractionWriter.toString()); However, no matter what I do I can't seem to avoid having

Why does this triple quoting solution fix path error?

雨燕双飞 提交于 2019-12-06 05:53:05
So I was running into a bit of a problem today with this bit of code: os.system("C:\Program Files (x86)\DOSBox-0.72\dosbox.exe") Upon execution I'd get this error message: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. I assumed it was something to do with either the white space or the brackets, so I did a bit of digging online and after countless of ineffective "solutions" involving escape characters, I ended up finding a rather strange solution; to surround the double quotes with another double and a single like so: os.system('""C:\Program

What would be the best way to pass a list from python to js using bottle?

怎甘沉沦 提交于 2019-12-06 05:47:38
问题 I am using Bottle as a web server and need to pass a python list to javascript. When I am doing just {{myList}}, Bottle escapes single quotes for strings in the list and shows them as ' JS, in turn, isn't very happy with what it gets. I managed to find a solution, but I don't think it's an optimal one. var tempList = '{{eval(myList)}}'.replace(/'/g, "'"); var myNewList = eval(tempList); I wonder, is there a better way to do this? upd: I moved the solution I found into the 'Answers' section.

Can't convert unicode symbols to cyrillic

拜拜、爱过 提交于 2019-12-06 05:19:46
问题 I have a bunch of documents persisted in Apache Lucene with some names in russian, and when I'm trying to print them out it looks like this "\u0410\u0441\u043f\u0430\u0440" , but not in cyrillic symbols. The project is in Scala. I've tried to fix this with Apache Commons unescapeJava method, but it didn't help. Are there any other options? Updated: Project is writen with Spray framework and returns json like this. { "id" : 0, "name" : "\u0410\u0441\u043f\u0430\u0440" } 回答1: I'm going to try

Regex expression to match whole word with special characters not working ? [duplicate]

佐手、 提交于 2019-12-06 03:59:59
问题 This question already has an answer here : Regex expression to match whole word ? (1 answer) Closed last year . I was going through this question C#, Regex.Match whole words It says for match whole word use "\bpattern\b" This works fine for match whole word without any special characters since it is meant for word characters only! I need an expression to match words with special characters also. My code is as follows class Program { static void Main(string[] args) { string str = Regex.Escape(

Escaping reserved words

安稳与你 提交于 2019-12-06 03:26:46
Sitecore provides a way of escaping words within a Sitecore query that contain characters that they don't like. Such characters include hyphens and spaces. In the interest of simplifying my life, I wrote a simple helper function that would escape every part of a Sitecore query, and it worked fine for a while: public static string EscapePath(string path){ return Regex.Replace(path, @"([^/]+)", "#$1#").Replace("#*#", "*"); } (the Replace("#*#","*") is in there because Sitecore doesn't like it when you wrap the asterisk in hashes). As I said, this worked fine for a while. Today, I came across a