escaping

Any way to escape a Go string in a regular expression?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 23:27:30
问题 I'm wanting to match ^(@|\s)*{{string}}:? whereas {{string}} is dynamically defined. It may have periods and dashes and any number of things in it and I really need for it to be escaped. PHP provides a preg_quote method that escapes all special characters safely. I was wondering if Go provides any sort of analog. 回答1: regexp.QuoteMeta does the deed. 来源: https://stackoverflow.com/questions/27415532/any-way-to-escape-a-go-string-in-a-regular-expression

django escapejs and simplejson

心不动则不痛 提交于 2019-12-08 19:46:12
问题 I'm trying to encode a Python array into json using simplejson.dumps: In [30]: s1 = ['test', '<script>'] In [31]: simplejson.dumps(s1) Out[31]: '["test", "<script>"]' Works fine. But I want to escape the strings first (using escapejs from Django) before calling simplejson.dumps: In [35]: s_esc Out[35]: [u'test', u'\\u003Cscript\\u003E'] In [36]: print simplejson.dumps(s_esc) ["test", "\\u003Cscript\\u003E"] My problem is: I want the escaped string to be: ["test", "\u003Cscript\u003E"] instead

magento escape string for javascript

て烟熏妆下的殇ゞ 提交于 2019-12-08 19:37:50
问题 Is there a helper function that will properly escape a string to be rendered as a single quote quoted JavaScript string literal? I know of jsQuoteEscape but it only handles quotes and does not treat \n & \r etc. so if my string is 'line1\nlineb' (i.e. two lines with a newline between them) and I use var jsvar='<?php echo $this->helper('myextension')->jsQuoteEscape($mystring); ?>'; I will get in the rendered content var jsvar='line1 line2'; which is a syntax error. Thanks, Eyal 回答1: Yes

Exit full screen when “esc” is pressed (using javascript with electron)

谁说我不能喝 提交于 2019-12-08 18:39:39
问题 I'm working on an app (with electron) and I would like users to be able to exit fullscreen mode when pressing "esc". I tried different methods, in vain. Here is the code who launch the app in a new browser window in fullscreen mode and display and HTML/CSS content : 'use strict'; const electron = require('electron'); // Module to control application life. const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; // Keep a global

Is there a way to escape a closing bracket for comments?

梦想的初衷 提交于 2019-12-08 18:30:38
问题 I'm adding comments to my Delphi code for documentation. One of the things I'm trying to document is the JSON structure, so I'm trying to put sample JSON data commented in the code. However, JSON widely uses the squiggly brackets { } , which coincidentally is also used for comments in Delphi. Because of this, I can't figure out a way to add these comments. Usually for documentation comment blocks I use { } , for example: { This unit does this and that. Use TSomeComponent to do bla bla } When

Escaping verbatim string literals

╄→尐↘猪︶ㄣ 提交于 2019-12-08 18:01:12
问题 I have the following string which won't compile: String formLookupPull = @"SELECT value1, '"+tableName+"', '"+columnName+"' FROM lkpLookups WHERE ""table"" = '" + tableName + "' and ""field"" = '" + columnName + "';"; The offending sections are : ""table"" = and ""field"" = The compiler is getting all mixed up on the escape sequence. Can anyone see what's wrong? 回答1: The problem is that not all the strings you are concatenating are verbatim string literals, only the first portion of the

Escaping Qualtrics piped text for use in javascript (more generally, how to safely escape user-generated text)

喜你入骨 提交于 2019-12-08 17:42:02
问题 In my Qualtrics survey I have a free-response (textbox) question. I'd like to get the response to this question into javascript so I can do some complicated text processing and post the result to an external page. It looks like the official Qualtrics way to do that is to use the piped text code: var answer = "${q://QID1/ChoiceTextEntryValue}" But this generates javascript code with the literal response inserted into the code. If a survey-taker puts a quote mark in their response, it will

Wordpress: How to unescape the results when using $wpdb->get_results?

痞子三分冷 提交于 2019-12-08 16:00:47
问题 To add a new rows to the database I use $wpdb->insert , and to get the rows I use $wpdb->get_results . The problem is that $wpdb->insert seems to be escaping the input. For example, a"b is saved as a\"b in the database. But, $wpdb->get_results doesn't seem to unescape back a\"b to a"b . Is this the correct behavior by design? Should I unescape the result of $wpdb->get_results manually? (What is the proper function for this?) 回答1: $wpdb->insert() and $wpdb->prepare() will escape data to

How to nest two `forfiles` loops properly (so that the inner body expands variables of both iteration levels)?

删除回忆录丶 提交于 2019-12-08 15:04:32
问题 I am trying to nest two forfiles loops so that the command of the inner loop receives @ variables from both the outer and the inner loop iteration. For the latter the @ variable replacement needs to be escaped for the outer loop so that the inner forfiles command receives the variable name. I have got a code snippet that enumerates a given directory ( C:\root ), and if the iterated item is a directory on its own, all the contained text files ( *.txt ) are listed. However, it does not work as

Prevent jQuery from escaping html entities

倖福魔咒の 提交于 2019-12-08 15:00:42
问题 I have some simple html editor. Let's say that user types following: <p>Ok, this just & sucks :) –</p> and it is saved to some variable: var content = "<p>Ok, this just & sucks :) –</p>"; Now, somewhere I'm using jQuery to append this text to some element: $(this).html(content); // where content is the string above The problem is that it is escaped: <p>Ok, this just &amp; sucks :) &ndash;</p> How can I achieve to have the exact string with &amp ; and &ndash ; and also to have < and not &lt ;