escaping

Understanding input escaping in PHP

前提是你 提交于 2019-12-05 16:04:40
One thing that's always confused me is input escaping and whether or not you're protected from attacks like SQL injection. Say I have a form which sends data using HTTP POST to a PHP file. I type the following in an input field and submit the form: "Hello", said Jimmy O'Toole. If you print/echo the input on the PHP page that receives this POST data, it comes out as: \"Hello\", said Jimmy O\'Toole. This is the point where it gets confusing. If I put this input string into (My)SQL and execute it, it'll go into the database fine (since quotes are escaped), but would that stop SQL injection? If I

How are strings escaped for each database extension in php?

三世轮回 提交于 2019-12-05 15:48:57
Before anyone jumps to conclusions as to the nature of this question, I already know about parameterized/prepared statements and use them whenever possible. Unfortunately, it is not always possible to use them when building dynamic queries. I'm interested in working with databases other than MySQL, but I can't easily find good sources as to how to escape strings for each database extension to prevent SQL Injection . The PHP docs list the following vendor specific database extensions. I've boldened the ones I'm most interested in: CUBRID dBase DB++ FrontBase filePro Firebird/InterBase Informix

Inserting HTML to golang template [duplicate]

二次信任 提交于 2019-12-05 15:20:12
This question already has an answer here: Go template.ExecuteTemplate include html 8 answers I have a template in golang where I have a string that looks something like this: <some_html> {{ .SomeOtherHTML }} </some_html> I'm expecting an output to be something like this: <some_html> <the_other_html/> </some_html> But instead I'm seeing something like this: <some_html> <the_other_html/< </some_html> I'm also trying to insert some JSON but golang is escaping characters and adding things like " in places they shouldn't be. How do I insert into an HTML template in golang without this happening?

Unescape HTML entities containing newline in Javascript?

≯℡__Kan透↙ 提交于 2019-12-05 14:52:36
If you have a string containing HTML entities and want to unescape it, this solution (or variants thereof) is suggested multiple times: function htmlDecode(input){ var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; } htmlDecode("<img src='myimage.jpg'>"); // returns "<img src='myimage.jpg'>" (See, for example, this answer: https://stackoverflow.com/a/1912522/1199564 ) This works fine as long as the string does not contain newline and we are not running on Internet Explorer version pre 10 (tested on version 9 and 8). If

WARNING: nonstandard use of escape in a string literal

旧巷老猫 提交于 2019-12-05 14:18:50
I have query to remove double space and convert it to single space. UPDATE tablename SET name=trim(regexp_replace(name,'\s\s+',' ', 'g')); It gives error: WARNING: nonstandard use of escape in a string literal HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. Erwin Brandstetter You are running an old version of Postgres with the setting escape_string_warning = on (default) and standard_conforming_strings = off ( outdated! , default is on since Postgres 9.1). The manual: escape_string_warning ( boolean ) When on, a warning is issued if a backslash ( \ ) appears in an ordinary

Escaping quotes from Rails Variables when using them for Javascript?

若如初见. 提交于 2019-12-05 12:16:03
问题 I am having problems when trying to use a rails variable within javascript code. For example, I might define a link_to_remote, with parameter :complete => "alert('my_var');" If my_var = "I'm testing." , then the javascript code will break due to the single quote closing the code prematurely. If I try using escape_javascript(my_var) so that the quote gets turned into \' , it doesn't seem to fix the problem. I've noticed that when you try alert('I\'m testing'); there's a problem, but if you do

Escape asterisk in Windows Batch File's FOR Loop

荒凉一梦 提交于 2019-12-05 12:15:14
When running the following code in a windows batch file everything works aside from the string containing the asterisk, which is skipped. Checking the passed parameters by number (i.e. echo(%~6 ) I can see the asterisk - it's only when passed to the FOR loop that I have an issue: @echo off setlocal enableextensions enabledelayedexpansion call:Concat cmd "this is a demo" " of concat functionality." " Hopefully it will work;" " but it doesn't when I pass an" " * asterisk" " character" echo !cmd! @goto:end @goto:eof :Concat ::Concatenates a given list of strings without including their quotes ::1

How should I escape characters inside this LIKE query?

前提是你 提交于 2019-12-05 11:05:58
I have a field in one of my tables that contains this string: !"#¤%&/()=?´`?=)(/&%¤#"!\'\'"' (Only for test purposes ofcourse). I've tried endless of queries to properly select this field, and without returning any errors of course, but I just can't seem to get it right. This is the query I'm using currently: SELECT * FROM mytable WHERE `column` LIKE '%!"#¤%&/()=?´`?=)(/&%¤#"!\\\'\\\'"\'%' Can anyone shed some light on what it is I'm not doing right? Are there any other characters (other than ' ) that I should escape? I haven't read about it anywhere... (I did however try adding backslashes

What's the Magic Behind Escape(\\) Character

馋奶兔 提交于 2019-12-05 10:03:39
How does the C/C++ compiler manipulate the escape character ["\"] in source code? How is compiler grammar written for processing that character? What does the compiler do after encountering that character? Most compilers are divided into parts: the compiler front-end is called a lexical analyzer or a scanner. This part of the compiler reads the actual characters and creates tokens. It has a state machine which decides, upon seeing an escape character, whether it is genuine (for example when it appears inside a string) or it modifies the next character. The token is output accordingly as the

Remove the escape sequence '\\' from string to convert it to XmlDocument

隐身守侯 提交于 2019-12-05 10:01:38
I have a web service which returns a struct object, so I get the response as the following XML string. Now I need to load it into XmlDocument object but how do I get rid of the escape sequences in the string. The '\' with every '"' is causing error. <?xml version=\"1.0\" encoding=\"utf-8\"?> <Quote xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.org/\"> <price>19656</price> </Quote> Use Regex.Unescape method. String unescapedString = Regex.Unescape(textString); user3931102 Regex.Unescape doesn't un-escape " .