Questions tagged [escaping]

Escaping is the process of applying an alternate meaning to a character or set of characters.

Filter by
Sorted by
Tagged with
2 votes
2 answers
155 views

Wielding .NET masterfully to encode non-alphanumeric characters into utf-8 hex representation

I have these two methods that work, but I also hate because they almost certainly can be improved. I'm hoping to gain some guidance from others who are more knowledgable of .NET's offering for ...
Greg H's user avatar
  • 23
1 vote
2 answers
120 views

Parse string using character value for Unicode characters

I added the getCValue method to reduce the cyclomatic complexity, but the cyclomatic complexity still persists. How can I reduce it? Can I change this code using ...
stromboli's user avatar
0 votes
3 answers
557 views

url encoding and storing (JS, PHP, MySQL) [closed]

This question is about how best to encode, send and store information between JavaScript, PHP, and MySQL I am doing a GET request from HTML/JavaScript to my PHP server, which is then storing the data ...
ControlAltDel's user avatar
3 votes
1 answer
156 views

Ask for user input and again on the same line

A function that asks for user input according to some criteria and again on the same line if the criteria is not met. It requires that escape character sequences be enable. ...
user avatar
1 vote
2 answers
635 views

Golang - Splitting a string by a separator not prefixed by an escape string

I need to split a string by a separator but don't want to split if the separator is prefixed by the escape string. For example: ...
Cookie04's user avatar
  • 125
1 vote
1 answer
217 views

Method encodes all less than (<) characters in a HTML string, but not the HTML tags

I am cleaning a HTML string to encode the less than sign (<) to a HTML entity (&lt;), but leaving the HTML tags as they are. An example is converting ...
Scho's user avatar
  • 113
6 votes
1 answer
276 views

binary data shell echo generator

edit: here is a cleaned-up version incorporating most (but not all) feedback, thanks guys; https://gist.github.com/divinity76/79efd7b8c0d7849b956cd194659c98e5 edit2, 2021-07-16: found a bug (possible ...
hanshenrik's user avatar
1 vote
0 answers
1k views

Escaping invalid XML characters (e.g. for the Java DOM API)

I want to save and load an arbitrary Java String in a Text node in a XML file using the Java DOM API. The ...
stonar96's user avatar
  • 111
7 votes
1 answer
244 views

Rust echo implementation that supports command line options

I rewrote echo from the manpage to learn Rust, and got the following: ...
Cyril D.'s user avatar
  • 456
6 votes
1 answer
78 views

POSIX+ implementations of echo(1)

Ever wanted a strictly conformant echo(1) implementation on your system? Wait no more: I've built it! What is it? My first large-ish body of C code in a while. ...
D. Ben Knoble's user avatar
2 votes
1 answer
1k views

PHP santization of textarea input

My application will accept textarea content that is submitted by a user, and i would like some people to review my code to make sure there is no security vulnerability such as XSS. My mySQL column ...
pabloBar's user avatar
2 votes
1 answer
112 views

Unquoting booleans, numbers, etc. in a JSON string

I have a method that takes a JSON string as input and "fixes" it. By that, I mean, that the JSON string comes in with all values quoted. My method un-quotes the values that shouldn't be quoted (i.e. ...
SledgeHammer's user avatar
1 vote
2 answers
437 views

Balanced parenthesis, with backslash escaping

Given a Balanced Parenthesis problem. "Balanced Parenthesis Create a program that checks if in a given string expression all the parenthesis are balanced. For Example: (test) - valid ...
MAttti's user avatar
  • 35
3 votes
1 answer
148 views

htmlspecialchars() equivalent in C

I'm trying to write an equivalent of PHP's htmlspecialchars() in C. What is my implementation missing or doing wrong? ...
wispi's user avatar
  • 185
6 votes
1 answer
3k views

Python program that obfuscates an email address

I decided to resume my (limited) Python skills after not coding for a long time. Here's a very simple self-contained program to convert the characters of an email address into their HTML entities (...
dr_'s user avatar
  • 235
4 votes
1 answer
540 views

Displaying text extracted from XML using PHP simplexml

I have this xml file and i am parsing it with php simplexml. My XML file looks like this: ...
eskimopest's user avatar
4 votes
2 answers
68 views

Escaped line reader

The idiomatic way of reading lines from a file doesn't work for my purposes because the files I'm dealing with might have lines that are escaped. I came up with the below (which seems to meet my needs)...
Kittoes0124's user avatar
  • 1,870
4 votes
2 answers
307 views

Interpreting strings with C-style escapes

I am working on a compiler that does a pretty heavy work on strings in order to get them correctly displayed. So far I have an algorithm that transforms a given string like (In plaintext): ...
NaCl's user avatar
  • 193
1 vote
0 answers
454 views

A class to stop XML parser from converting UTF-8 entity hex characters

I'm trying to stop the xml parser from converting the UTF-8 enitity hex codes to its character alternative and also not adding the extra space in self-closing nodes after parsing. I've created a ...
Don_B's user avatar
  • 145
5 votes
1 answer
264 views

Sublime Text plugin to modify text before it's pasted

It's my first plugin and it's super simple but there could easily be some things worth knowing from this e.g. Python coding practices and potential bugs. ...
Matt's user avatar
  • 2,568
0 votes
2 answers
949 views

XSS Protection from Query Strings in Java

Looking for input on the code below. Generally, the idea is to take a String representing a URL query string such as param1=blah&param2=blah and encode them to ...
Jason's user avatar
  • 385
3 votes
0 answers
2k views

Decoder for Content-Transfer-Encoding and Quoted-printable

Below are two utility functions I have written to help decode email messages in Mbox format. decodeTransfer decodes the message according to the Content-Transfer-...
Datagrammar's user avatar
1 vote
2 answers
143 views

Encoding arbitrary data for stream transmission

Basically, what this function should do is encode an arbitrary set of data in memory to a series of bytes that starts with 0x02, ends with ...
robbie's user avatar
  • 261
2 votes
1 answer
3k views

Escaping characters in a WMI Query

I've knocked up this code to allow me to query for specific service names using PowerShell. I'm after the executable (PathName) for the service, so the ...
JohnLBevan's user avatar
  • 1,333
8 votes
1 answer
117 views

String escaper in C

As part of my stupidly large project Concaten, I'm writing a string escaper. It's the majority of the part that turns string tokens (like "hello world" or ...
Nic's user avatar
  • 5,473
4 votes
1 answer
257 views

Raw replacement of space by %20 in Java

I tried coding this for practice. Is there a more memory-efficient way to work in place without using more arrays etc (using raw array operations)? ...
Jas's user avatar
  • 173
8 votes
5 answers
8k views

Write a method to replace all spaces in a string with %20

I have implemented a solution to this Cracking the Coding Interview question: Write a method to replace all spaces in a string with %20. You may assume that the string has sufficient space at the ...
TheLearner's user avatar
15 votes
3 answers
22k views

Escape user input for use in JS regex

I am building a highlight feature for search results on my website and need to escape the user's input so that I could highlight the matching string within the original text. The function ...
MonkeyZeus's user avatar
3 votes
0 answers
394 views

Escape Characters for LDAP/ADSI string

Below's some code I knocked up to escape the account name to be used in creating an ADSI reference to an account (e.g. escaping $sAmAccountName before using in <...
JohnLBevan's user avatar
  • 1,333
1 vote
1 answer
2k views

Converting bytes to an escaped hexadecimal string

I wrote this function to convert an array of bytes to a C/C++ string representation using hexadecimal escape codes (\xhh). Any suggestions are welcome: ...
glampert's user avatar
  • 17.1k
7 votes
2 answers
4k views

Efficient URL Escape (Percent-Encoding)

Here I have a simple algorithm to percent-encode any string. (Specification from Wikipedia; note that this is not compatible with URLEncoder.encode()) Is this an ...
Kent's user avatar
  • 173
4 votes
2 answers
198 views

Escape some char in a byte array

I am trying to construct a binary message packet. It needs to escape binary value 0 by appending extra 0 in front of it: ...
Tim's user avatar
  • 337
5 votes
2 answers
4k views

My method of escaping MySQL strings in C++

This is how I'm currently escaping MySQL strings in C++: ...
Zyre's user avatar
  • 143
4 votes
2 answers
4k views

Preventing XSS attacks with proper escaping

The following page simulates XSS attacks and successfully (?) prevents them. I want to know if I've missed any other major attack vectors (or small ones) and/or if anyone has suggestions as to ...
AmadeusDrZaius's user avatar
3 votes
1 answer
85 views

Escaping photo caption to avoid cross site script attack

I am a PHP newbie and this is part of a gallery code. I recently read about SQL injection and cross site scripting attack, I am trying to avoid that by html escaping on dynamically produced data. I am ...
user52432's user avatar
5 votes
1 answer
142 views

Sanitzing input on form submit with PHP

I was hacking around this morning and wanting to use automatically generate safe-to-use variables from $_POST. Probably not the best use of ...
bcr's user avatar
  • 315
6 votes
1 answer
799 views

Is this escape unescape function pair correct?

Is this example of an escape - unescape function correct? ...
Paul's user avatar
  • 163
7 votes
3 answers
1k views

Functions to escape CSS rules in PHP

Some context I've been tasked with supplying an escaping function to arbitrary CSS values that are entered through a form. The goals and caveats are: I know it's bad practice to let users input CSS. ...
Madara's Ghost's user avatar
3 votes
3 answers
300 views

More Pythonic version of finding substring with one glob-like expression

Giving the following example list the task is: find out whether the second expression is in the first one. * shall be considered as a wildcard for any character ...
ProfHase85's user avatar