escaping

How to escape strings for terminal in Ruby?

风格不统一 提交于 2019-11-30 06:06:19
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? Shellwords should work for you :) exec "/usr/bin/mplayer %s" % Shellwords.escape(song.file) In ruby 1.9.x, it looks like you have to require it first require "shellwords" But in ruby 2.0.x, I

Generating html with batch .. escape quotes

安稳与你 提交于 2019-11-30 06:02:51
问题 This is supposed to generate the hierarchy to a web document with the different files, it's because I'm lazy I made this. @echo off echo. echo This program will generate the base folder for a new website .. . pause md folders echo > folders/default.html "<html> /* More content */ </html>" echo > folders/style.css " /* All the standards i always use */ " echo > folders/javascript.js " /* All the standards i always use */ " echo. exit It also work but the problem is, I cannot remove/escape the

How to escape single quotes in Python on a server to be used in JavaScript on a client

谁说胖子不能爱 提交于 2019-11-30 05:52:15
Consider: >>> sample = "hello'world" >>> print sample hello'world >>> print sample.replace("'","\'") hello'world In my web application I need to store my Python string with all single quotes escaped for manipulation later in the client browsers JavaScript. The trouble is Python uses the same backslash escape notation, so the replace operation as detailed above has no effect. Is there a simple workaround? Use: sample.replace("'", r"\'") or sample.replace("'", "\\'") As a general solution for passing data from Python to Javascript, consider serializing it with the json library (part of the

How to avoid System.Xml.Linq.XElement escaping HTML content?

℡╲_俬逩灬. 提交于 2019-11-30 05:21:31
问题 I'm using the XElement object to build some HTML in the code-behind on an ASP.NET page. I may or may not add some XAttributes to this XElement as I go along, in the following fashion: var elmnt = new XElement("div", new XAttribute("id", "myDiv"), ); Now, if I want to add some content into myDiv which contains HTML, the XElement automatically escapes this which, in my situation, is undesirable. So if I have: var elmnt = new XElement("div", new XAttribute("id", "myDiv"), "<span id='content'

How to prevent auto escape in Django templates?

假如想象 提交于 2019-11-30 05:15:39
In the docs it says: The only exceptions are variables that are already marked as “safe” from escaping, either by the code that populated the variable, or because it has had the safe or escape filters applied." How does the "populated the variable" part work ? I'm actually looking for a way to declare a template tag as safe in the view. I somehow think it's not a good idea to let a designer decide. My co-worker will just add it whenever she 'thinks' it's a good idea. https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs Django has a subclass of strings called safe strings

Single quote handling in a SQL string

柔情痞子 提交于 2019-11-30 04:59:09
I have an application where the values in the text field are sent to the database. For example I have a form with one field (text box). When I press Ok button then the content of the text field is inserted as a record into a table. I'm just trimming and extracting the text box's text into variable and passing it to my SQL string. The problem is that whenever something like "It's" or "Friend's" the single quote is identified as the end of string. In Delphi I have seen something like QuotedString to avoide this. Any ideas from you? Don't ever build SQL statements like that, it's very unsafe

Uri.EscapeDataString weirdness

霸气de小男生 提交于 2019-11-30 04:47:06
问题 Why does EscapeDataString behave differently between .NET 4 and 4.5? The outputs are Uri.EscapeDataString("-_.!~*'()") => "-_.!~*'()" Uri.EscapeDataString("-_.!~*'()") => "-_.%21~%2A%27%28%29" The documentation By default, the EscapeDataString method converts all characters except for RFC 2396 unreserved characters to their hexadecimal representation. If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, the EscapeDataString method converts

how to escape <> in javascript underscore template?

元气小坏坏 提交于 2019-11-30 04:46:19
问题 when using underscore template i want to interpolate a value in anchor's href attribute like a(href= "<%= id %>", class='products') //underscore template in jade but the out put is <a href="&lt;% id %&gt;" class="products"> so how to escape the < and > sign , and interpolate the value correctly? 回答1: Use != instead of = to unescape. In your case: a.products(href!="<%= id %>") 来源: https://stackoverflow.com/questions/12362290/how-to-escape-in-javascript-underscore-template

escaping backslash in java string literal [duplicate]

这一生的挚爱 提交于 2019-11-30 03:42:38
问题 This question already has answers here : Replacing single '\' with '\\' in Java (6 answers) Closed 4 years ago . I am using Java for a while and come up with this problem: I use hard-coded paths in windows like "D:\Java-code\JavaProjects\workspace\eypros\src" The problem is that I need to escape the backslash character in order to use it with string. So I manually escape each backslash: "D:\\Java-code\\JavaProjects\\workspace\\eypros\\src" Is there a way to automatically take the unescaped

Escaping user input from database necessary?

人走茶凉 提交于 2019-11-30 03:31:05
So I know about MySQL injection and always escape all my user input before putting it in my database. However I was wondering, imagine a user tries to submit a query to inject, and I escape it. What if I then at a later moment take this value from the database, and use it in a query. Do I have to escape it again? So: ( sql::escape() contains my escape function) $userinput = "'); DROP `table` --"; mysql_query("INSERT INTO `table` (`foo`,`bar`) VALUES ('foobar','".sql::escape($userinput)."')"); // insert php/mysql to fetch `table`.`bar` into $output here mysql_query("INSERT INTO `table2` (`foo`,