escaping

Parsing newline characters in textareas without allowing all html tags

荒凉一梦 提交于 2019-12-05 00:14:14
问题 I have a textarea field where users can enter content. When it comes to displaying their entry on a page, rails returns \n for each line break, which appears as no break at all for html on the page. From what I gather, the standard way of getting around this is a .gsub command, replacing \n with <br /> , and then a .html_safe on the end to ensure the <br /> renders. The problem is, I don't want to html_safe the content - html should still be replaced, but <br /> tags should be injected into

Replace a question mark (?) with (\\\\?)

巧了我就是萌 提交于 2019-12-04 23:49:22
I am trying to define a pattern to match text with a question mark (?) inside it. In the regex the question mark is considered a 'once or not at all'. So can i replace the (?) sign in my text with (\\?) to fix the pattern problem ? String text = "aaa aspx?pubid=222 zzz"; Pattern p = Pattern.compile( "aspx?pubid=222" ); Matcher m = p.matcher( text ); if ( m.find() ) System.out.print( "Found it." ); else System.out.print( "Didn't find it." ); // Always prints. You need to escape ? as \\? in the regular expression and not in the text . Pattern p = Pattern.compile( "aspx\\?pubid=222" ); See it You

How to pass in a null character in a command line argument in C?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 23:46:36
I would still like to know how to pass in a null character as a command line argument, maybe so that a single string can be passed in as an argument in the form: "to\0be\0or\0not\0to\0be\0" And then parse it. However the program would treat this string as: "to\\0be\\0or\\0not\\0to\\0be\\0" How can I work around this? Is there any way? You cannot. The C program receives arguments as zero-terminated strings. Such a string cannot contain a null character, by definition. If you want to pass a null character, then you must somewhat encode it with some syntax, and your C program must then decode it

How to escape underscores in Postgresql

南笙酒味 提交于 2019-12-04 22:44:15
When searching for underscores in Postgresql, literal use of the character _ doesn't work. For example, if you wanted to search all your tables for any columns that ended in _by , for something like change log or activity information, e.g. updated_by , reviewed_by , etc., the following query almost works: SELECT table_name, column_name FROM information_schema.columns WHERE column_name LIKE '%_by' It basically ignores the underscore completely and returns as if you'd searched for LIKE '%by' . This may not be a problem in all cases, but it has the potential to be one. How to search for

To escape many _ in LaTeX efficiently

扶醉桌前 提交于 2019-12-04 22:40:40
How can you escape _ without the use of \_ ? This is the example of the question word_a_a_a_a_a_b_c_dd There is one function which you can use for this. However, I cannot remember its name. Are you thinking of the underscore package, which redefines the underscore symbol so that you don't have to escape it in text mode? See here . Other than verbatim I wouldn't know. Verbatim environment: \begin{verbatim} word_a_a_a_a_a_b_c_dd \end{verbatim} Inline: \verb|word_a_a_a_a_a_b_c_dd| I couldn't get the underscore package to work, so I used the url package: \usepackage{url} \urlstyle{sf} % or rm,

Escaping quotes in string

亡梦爱人 提交于 2019-12-04 22:39:55
I have a python dictionary e.g.: [{"pk":"1","name":"John","size":"1/4" "},{},{},etc] That size is 1/4 inch,how would I "escape" that quote? So it still would display it as 1/4", Its a list of things, so I cant just manually code it like 1/4\" , I tried replace('"','\"') EDIT: The orginal list is a textfield in my Django models: [{'pk': '91', 'size': '', 'name': 'Thread Flat For BF', 'quantity': '2'}, {'pk': '90', 'size': '', 'name': 'Blade Holders Straight ', 'quantity': '26'},{'size':'3"','name':'2m 1/4" Round bar', 'quantity':'43'},{'size':'5','name':'2m 1/8" Round bar', 'quantity':'4'}]

Prevent URL-encoding of characters in link in MediaWiki

∥☆過路亽.° 提交于 2019-12-04 21:59:08
I.e.: How to suppress substitution/replacement of characters with its html entities in a MediaWiki link? I need to insert a link looking like this, pipes ( | ) included, into a MediaWiki article: http://www.somesite.asdf/#|param1|param2|param3 The target site does not accept %7C or | as pipe-substitutes in its URL. Ergo, the following URLs are invalid: http://www.somesite.asdf/#%7Cparam1%7Cparam2%7Cparam3 http://www.somesite.asdf/#|param1|param2|param3 When I type the link into the MediaWiki-article like: http://www.somesite.asdf/#|param1|param2|param3 ... it results in a link pointing to:

When i need to escape Html string?

强颜欢笑 提交于 2019-12-04 21:12:02
问题 In my legacy project i can see the usage of escapeHtml before string is sent to browser. StringEscapeUtils.escapeHtml(stringBody); I know from api doc what escapeHtml does.here is the example given:- For example: "bread" & "butter" becomes: "bread" & "butter". My understanding is when we send the string after escaping html its the browser responsibility that converts back to original characters. Is that right? But i am not getting why and when it is required and what happens if we send the

What's the best way to escape user input for Regular Expressions in MySQL?

六月ゝ 毕业季﹏ 提交于 2019-12-04 20:48:51
问题 I'd like to take user input, denoted as $dangerous_string, and use it as part of a RegEx in a MySQL query. What's the best way to go about doing this? I want to use the user's string as a literal -- if it contains any characters that mean something in MySQL RegEx, those characters should not actually affect my Regular Expression. $dangerous_string = $_GET["string"]; //do something here $dangerous_string = what_goes_here($dangerous_string); $sql = "SELECT * FROM table WHERE search_column REGEX

bash tips needed for understanding how to escape characters in command-line

跟風遠走 提交于 2019-12-04 20:34:11
My knowledge of commandline bash is missing on a particular area: I constantly forget how to properly escape characters. Today I wanted to echo this string into a file: #!/bin/env bash python -m SimpleHTTPServer However, this fails: echo "#!/bin/env bash\npython -m SimpleHTTPServer" > server.sh && chmod +x server.sh -bash: !/bin/env: event not found That's right: Remember to escape ! or bash will think it's a special bash event command. But I can't get the escaping right! \! yields \! in the echoed string, and so does \\! . Furthermore, \n will not translate to a line break. Do you have some