escaping

Do curly braces inside json string objects need to be escaped?

前提是你 提交于 2019-12-18 18:54:05
问题 This string is part a JSON object/file: "Mask" : "{0}(CASE WHEN {1} = {2} THEN {3} ELSE 0 END) {4}" Will JSON recognize that as part of standard JSON notation or do I need to escape those curly braces s somehow? If so, how does one escape curly braces in JSON? 回答1: No . Curly braces do not have to be escaped in JSON. 回答2: No, curly braces do not have to be escaped in JSON strings. JSON is defined in RFC 7159. The Section 7: Strings lists the string characters that must be escaped: All Unicode

how can i escape '\xff\xfe' to a readable string

自闭症网瘾萝莉.ら 提交于 2019-12-18 18:36:11
问题 i see a string in this code: data[:2] == '\xff\xfe' i don't know what '\xff\xfe' is, so i want to escape it ,but not successful import cgi print cgi.escape('\xff\xfe')#print \xff\xfe how can i get it. thanks 回答1: You cannot escape or encode an invalid string. You should understand that you are working with strings and not byte streams and there are some characters you cannot accept in them, first of them being 0x00 - and also your example that is happening to be a BOM sequence. So if you need

jquery escape square brackets to select element

本小妞迷上赌 提交于 2019-12-18 17:06:33
问题 Consider a input element <input id="meta[152][value]" type="text" /> Here the input field is dynamically generated. I need to select that field. So I used, alert($('#meta[152][value]').val()); But this seems to be invalid. After searching I found, that the "square brackets" need to be escaped like #meta\\[152\\]\\[value\\] So how to do that ? I currently use this code, var id = "#meta[152][value]" // (I get this value by another method) I need the escaping to be done here. So that i can use

Executing shell command in background from ruby with proper argument escaping

倾然丶 夕夏残阳落幕 提交于 2019-12-18 13:06:05
问题 I have to run a command in the background but I want to have proper escaping for its parameter. system("rake send_mails subject='#{params[:subject]}' 2> /dev/null 1> /dev/null &"); If I write system("rake", "send_mails", params[:subject]) then I don't have "place" for redirections and the & sign. If I don't I do not have escaping for the subject parameter. How can I resolve this? 回答1: In Ruby 1.9, try Process.spawn: # Spawn a new process and run the rake command pid = Process.spawn({"subject"

Escape special HTML characters in Python

旧城冷巷雨未停 提交于 2019-12-18 12:55:06
问题 I have a string where special characters like ' or " or & (...) can appear. In the string: string = """ Hello "XYZ" this 'is' a test & so on """ how can I automatically escape every special character, so that I get this: string = " Hello "XYZ" this 'is' a test & so on " 回答1: In Python 3.2, you could use the html.escape function, e.g. >>> string = """ Hello "XYZ" this 'is' a test & so on """ >>> import html >>> html.escape(string) ' Hello "XYZ" this 'is' a test & so on ' For earlier versions

Escape comment character (#) in git commit message [duplicate]

走远了吗. 提交于 2019-12-18 12:47:39
问题 This question already has answers here : Start a git commit message with a hashmark (#) (8 answers) Closed 5 years ago . I have set mcedit as my editor for git commit messages. By default it ignores any lines starting with the # character. However odd this may seem, I need to be able to have the my commit message looking like this: #FOO-123: Implement bar foo Committing work in progress The #FOO-123: ... is actually the key + title of an issue in our tracker. The tracker can automatically

PHP ldap_add function to escape ldap special characters in DN syntax

自作多情 提交于 2019-12-18 12:29:09
问题 I'm trying to add some users to my Ldap DB but I get some errors (invalid dn syntax) when I use some special characters like ",.". I need a function that escape all characters. I try preg_quote but I get some errors in some cases. Thanks in advance Code: $user = 'Test , Name S.L'; if(!(ldap_add($ds, "cn=" . $user . ",".LDAP_DN_BASE, $info))) { include 'error_new_account.php'; } 回答1: EDIT Jan 2013: added support for escaping leading/trailing spaces in DN strings, per RFC 4514. Thanks to

How to escape strings for terminal in Ruby?

*爱你&永不变心* 提交于 2019-12-18 12:09:33
问题 I am attempting to start mplayer. My filename contains spaces and these should be escaped. This is the code I am using: @player_pid = fork do exec "/usr/bin/mplayer #{song.file}" end where #{song.file} contains a path like "/home/example/music/01 - a song.mp3" . How can I escape this variable properly (and possible other weird characters that the title may contain) so the terminal will accept my command? 回答1: Shellwords should work for you :) exec "/usr/bin/mplayer %s" % Shellwords.escape

Using encodeURI() vs. escape() for utf-8 strings in JavaScript

此生再无相见时 提交于 2019-12-18 11:53:07
问题 I am handling utf-8 strings in JavaScript and need to escape them. Both escape() / unescape() and encodeURI() / decodeURI() work in my browser. escape() > var hello = "안녕하세요" > var hello_escaped = escape(hello) > hello_escaped "%uC548%uB155%uD558%uC138%uC694" > var hello_unescaped = unescape(hello_escaped) > hello_unescaped "안녕하세요" encodeURI() > var hello = "안녕하세요" > var hello_encoded = encodeURI(hello) > hello_encoded "%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94" > var hello_decoded =

How to read quoted text containing escaped quotes

喜你入骨 提交于 2019-12-18 11:30:35
问题 Consider the following comma separated file. For simplicity let it contain one line: 'I am quoted','so, can use comma inside - it is not separator here','but can\'t use escaped quote :=(' If you try to read it with the command table <- read.csv(filename, header=FALSE) the line will be separated to 4 parts, because line contains 3 commas. In fact I want to read only 3 parts, one of which contains comma itself. There quote flag comes for help. I tried: table <- read.csv(filename, header=FALSE,