escaping

Filesystem filename escape? C#

风流意气都作罢 提交于 2019-12-05 05:30:48
I am allowing the user to choose any username he wants and it can be anything at all such as AC♀¿!$"Man'@ Now i need to create a directory for him. What function i use to escape the text so i dont a FS problem/exception? Use Path.GetInvalidFileNameChars or Path.GetInvalidPathChars to check for characters to remove. http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars.aspx Whether you replace invalid characters or remove them, there's always going to be the possibility of collisions. If I were you, I'd have a separate primary key for the user (a GUID perhaps) and use

React app rendering html entities such as ampersand as escaped

时光毁灭记忆、已成空白 提交于 2019-12-05 04:51:29
I have a React app embedded in Wordpress page. It pulls content from a JSON api and displays it in various areas. My problem is that all of the text content that comes from the api displays as escaped charachters i.e & displays where an ampersand should be. My wordpress page has <meta charSet="utf-8" /> which I would normally expect to convert this, but is having no effecton the React content. Is it because the rendering is done within React? In which case do I need to set React somehow to be using UTF-8? HTML (including entities) will be rendered as a string when being rendered as an

Should I escape an expected integer value using mysql_real_escape_string or can I just use (int)$expectedinteger

橙三吉。 提交于 2019-12-05 04:30:19
is it safe to use cast (int) instead of escaping? class opinion { function loadbyopinionid($opinionid){ $opinionid=(int)$opinionid; mysql_query("select * from fe_opinion where opinionid=$opinionid"); //more code } } mysql_real_scape_string is for STRINGS . it will not make an integer 'safe' for use. e.g. $safe = mysql_real_escape_string($_GET['page']); will do NOTHING where $_GET['page'] = "0 = 0"; because there's no SQL metacharacters in there. your query would end up something like SELECT ... WHERE somefield = 0 = 0 However, doing intval() will convert that 0=0 into a plain 0 . Yes it is

Using decode() vs. regex to unescape this string

此生再无相见时 提交于 2019-12-05 04:21:44
I have the following string and I'm trying to figure out the best practice for unescaping it. The solution has to be somewhat flexible in that I'm receiving this input from an API and I can't be absolutely certain that the current character structure ( \n as opposed to \r ) will always be the same. '"If it ain\'t broke, don\'t fix it." \nWent in for a detailed car wash.\nThe attendants raved-up my engine when taking the car into the tunnel. NOTE: my car is...' This regex seems like it should work: text_excerpt = re.sub(r'[\s"\\]', ' ', raw_text_excerpt).strip() I've aso read that decode()

Ruby: Escaping special characters in a string

ε祈祈猫儿з 提交于 2019-12-05 04:04:42
I am trying to write a method that is the same as mysqli_real_escape_string in PHP. It takes a string and escapes any 'dangerous' characters. I have looked for a method that will do this for me but I cannot find one. So I am trying to write one on my own. This is what I have so far (I tested the pattern at Rubular.com and it worked): # Finds the following characters and escapes them by preceding them with a backslash. Characters: ' " . * / \ - def escape_characters_in_string(string) pattern = %r{ (\'|\"|\.|\*|\/|\-|\\) } string.gsub(pattern, '\\\0') # <-- Trying to take the currently found

Replacement for javascript escape?

天涯浪子 提交于 2019-12-05 03:17:17
I know that the escape function has been deprecated and that you should use encodeURI or encodeURIComponent instead. However, the encodeUri and encodeUriComponent doesn't do the same thing as escape. I want to create a mailto link in javascript with Swedish åäö. Here are a comparison between escape, encodeURIComponent and encodeURI: console.log("mailto:?subject="+escape(subject)+"&body=" + escape(body)); console.log("mailto:?subject="+encodeURIComponent(subject)+"&body=" + encodeURIComponent(body)); console.log("mailto:?subject="+encodeURI(subject)+"&body=" + encodeURI(body)); Output: mailto:

Uri.EscapeUriString with square braces

橙三吉。 提交于 2019-12-05 03:12:44
Something of a strange question but let's see what kind of response it gets... If I code a console app (VS 2013, .NET 4.5.1) and execute this line of code: Uri.EscapeUriString("[") I get this: [ However if I execute the same thing (well, technically Uri.EscapeUriString("[").Dump() ) in LINQPad on my machine I get this: %5B To further complicate things, according to this post Uri.EscapeUriString("[") should indeed return %5B .The post was written on 27/06/2012. I'm thinking that perhaps LINQPad is referencing an older DLL than that used by VS, but that would imply that EscapeUriString has

EscapeDataString having differing behaviour between Powershell IDE and Powershell console

一个人想着一个人 提交于 2019-12-05 02:56:53
I'm a bit confused with this issue! I'm building a bigger script and it was working in the ISE but not in a powershell console. I've managed to track it down to the [System.Uri]::EscapeDataString function which seems to be behaving differently between the different environments, for example in my powershell console () ' & ! are not being escaped, where as in the IDE they are all being escaped. Am I missing something? My test code: [System.Uri]::EscapeDataString("/?:@%!$&'/*+,;=()") ISE output: %2F%3F%3A%40%25%21%24%26%27%2F%2A%2B%2C%3B%3D%28%29 Powershell Console output: %2F%3F%3A%40%25!%24%26

VS Code snippet - escape ${file}

浪尽此生 提交于 2019-12-05 02:53:51
I'd like to create a snippet in VS Code, which includes exact string ${code} . However, when I enter it in this form, VS Code tries to interpret it as snippet parameter. How should I escape it properly? "}" AND "$" can be escaped with "\\". Some cases "$" can be escaped with "$$" but not in your case. Your snippet should look like this. "Return Code With Squirly And Dollar": { "prefix": "code_snippet", "body" : [ "\\${code\\}" ], "description": "Code Snippet" } This should help you 来源: https://stackoverflow.com/questions/42669459/vs-code-snippet-escape-file

Escape from XSS vulnerability maintaining Markdown syntax?

孤人 提交于 2019-12-05 02:51:25
问题 I'm planning to use Markdown syntax in my web page. I will keep users input (raw, no escaping or whatever) in the database and then, as usual, print out and escape on-the-fly with htmlspecialchars(). This is how it could look: echo markdown(htmlspecialchars($content)); By doing that I'm protected from XSS vulnerabilities and Markdown works. Or, at least, kinda work. The problem is, lets say, > syntax (there are other cases too, I think). In short, to quote you do something like this: > This