escaping

How to escape indicator characters (i.e. : or - ) in YAML

早过忘川 提交于 2019-12-17 07:06:05
问题 In a config file, I have a key to which I wish to assign a URL. The problem is that YAML interprets : and - characters as either creating mappings or lists, so it has a problem with the line url: http://www.example-site.com/ (both because of the colon following http and the hyphen in the middle) Is there an explicit way to escape ':' and '-' ? Or would it work to just put the whole thing in single quotes and call it a day? 回答1: Quotes: "url: http://www.example-site.com/" To clarify, I meant

What characters have to be escaped to prevent (My)SQL injections?

烈酒焚心 提交于 2019-12-17 06:43:29
问题 I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following characters: \0 \n \r \ ' " \Z Now, I looked into OWASP.org's ESAPI security library and in the Python port it had the following code (http://code.google.com/p/owasp-esapi-python/source/browse/esapi/codecs/mysql.py): """ Encodes a character for MySQL. """ lookup = { 0x00 : "\\0", 0x08 : "\\b", 0x09 : "\\t", 0x0a : "\\n", 0x0d : "\\r", 0x1a : "\\Z", 0x22 : '\\"', 0x25 : "\\%", 0x27 : "

printing “<html>” using html

可紊 提交于 2019-12-17 06:16:27
问题 How do I print the "html" tag, including '<' and '>'? How can I do this for any tag, without using text areas and Javascript? 回答1: Use HTML character references: <html> Should output <html> 回答2: Try doing: <html> 回答3: Special characters in HTML, such as '<', '>', '"' and '&' can be printed using the following format: &name; where name would be replaced by a character name. The most common would then be < = < (less than) > = > (greater than) & = & (ampersand) " = " (double quote) So to write

How do I write the escape char '\' to code

一个人想着一个人 提交于 2019-12-17 06:15:45
问题 How to escape the character \ in C#? 回答1: You just need to escape it: char c = '\\'; Or you could use the Unicode escape sequence: char c = '\u005c'; See my article on strings for all the various escape sequences available in string/character literals. 回答2: You can escape a backslash using a backslash. //String string backslash = "\\"; //Character char backslash = '\\'; or You can use the string literal. string backslash = @"\"; char backslash = @"\"[0]; 回答3: use double backlash like so "\" "

Disable HTML escaping in erb templates

时光毁灭记忆、已成空白 提交于 2019-12-17 05:05:12
问题 In a Rails 3 application I have a domain class where one attribute stores pure HTML content (it's a blog app, the domain class is Post). In the ERB templates, I need to display the content of the attribute as it was formmated, with the HTML tags in place. But, Rails is escaping all HTML tags! How can I disable this behaviour for this class attribute? Example: somePost = Post.new somePost.content = "<strong> Hi, i'm here! </strong>" In the erb template: <%= somePost.content %> The HTML

How to search for slash (\) in MySQL? and why escaping (\) not required for where (=) but for Like is required?

懵懂的女人 提交于 2019-12-17 05:04:49
问题 Consider this QUERY (DEMO IS HERE) (SELECT * FROM `titles` where title = 'test\\') UNION ALL (SELECT * FROM `titles` where title LIKE 'test\\\\') Output: | ID | TITLE | -------------- | 1 | test\ | | 1 | test\ | QUESTION: Why no extra (\) required for (=) but for (like) additional \\ is required? Its clear that MySQL escaped the (test\) with (test\\) then using (test\\\\) is logical for LIKE. Table information: CREATE TABLE IF NOT EXISTS `titles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title

How to search for slash (\) in MySQL? and why escaping (\) not required for where (=) but for Like is required?

99封情书 提交于 2019-12-17 05:04:30
问题 Consider this QUERY (DEMO IS HERE) (SELECT * FROM `titles` where title = 'test\\') UNION ALL (SELECT * FROM `titles` where title LIKE 'test\\\\') Output: | ID | TITLE | -------------- | 1 | test\ | | 1 | test\ | QUESTION: Why no extra (\) required for (=) but for (like) additional \\ is required? Its clear that MySQL escaped the (test\) with (test\\) then using (test\\\\) is logical for LIKE. Table information: CREATE TABLE IF NOT EXISTS `titles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title

How to escape a string for use in Boost Regex

夙愿已清 提交于 2019-12-17 05:01:55
问题 I'm just getting my head around regular expressions, and I'm using the Boost Regex library. I have a need to use a regex that includes a specific URL, and it chokes because obviously there are characters in the URL that are reserved for regex and need to be escaped. Is there any function or method in the Boost library to escape a string for this kind of usage? I know there are such methods in most other regex implementations, but I don't see one in Boost. Alternatively, is there a list of all

Escape Quote in C# for javascript consumption

随声附和 提交于 2019-12-17 04:59:06
问题 I have a ASP.Net web handler that returns results of a query in JSON format public static String dt2JSON(DataTable dt) { String s = "{\"rows\":["; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { s += "{"; for (int i = 0; i < dr.Table.Columns.Count; i++) { s += "\"" + dr.Table.Columns[i].ToString() + "\":\"" + dr[i].ToString() + "\","; } s = s.Remove(s.Length - 1, 1); s += "},"; } s = s.Remove(s.Length - 1, 1); } s += "]}"; return s; } The problem is that sometimes the data returned

How do I pass in the asterisk character '*' in bash as arguments to my C program?

馋奶兔 提交于 2019-12-17 04:05:34
问题 Let's say I have a C program, and I run it from bash: $ ./a.out 123 * The program would output all the command line arguments, but it will show these instead: Argument 1: 123 Argument 2: a.out What can I do in my program to fix this? 回答1: The shell is replacing the asterisk with the name of each file in the directory. To pass a literal asterisk, you should be able to escape it: $ ./a.out 123 \* 回答2: Another option is to use set -f to turn off expansion. Compare: echo * v.s. set -f echo * You