views:

30

answers:

5

Need advice on what to name functions that do this

  • Perform operations on strings before inserting into db to protect from MySQL injection
  • Converts HTML special characters

Ex:

enter_db()
exit_db()

However, these function names sound kinda corny. Any suggestions or advice on other names? Thanks!

A: 

Let call them 'encode' (make code) and decode (make it not a code).

NawaMan
A: 

Here us what I would use: Input_Validation_Function()

HTML_Char_converter()

I know those might not be the best names. I hope it helps though.

Alos
+1  A: 

My database connection generally resides in a wrapper, so there's a bit of context for the functions:

//escapes data using standard methods - ie. mysql_real_escape_string()
$db->escapeData();

It sounds like you're making these functions external as part of a procedural library, and they do a little extra work on the string, so I'd probably go with something like:

sanitizeDbData();

I'm a PHP programmer, and PHP has a built in htmlspecialchars() function. It's got a nice simplicity to it. If you're not using PHP, I'd simply make htmlSpecialChars() the conversion function, or possibly htmlEntities().

zombat
A: 

It sounds like you want to "scrub" a string for an problems before dumping it into your DB. You could think of this as a conversion function from one type of string to another type of string. You could then name your function RawStringToSafeString or SafeStr_from_RawStr or something similar. If you need functions in the other direction, then the naming is clear.

Converting html special characters would be similar: RawStringToConvertedString, etc. This reduces complexity because you only have to keep track of what type of string you're dealing with, not what conceptual actions have been performed on them.

This is a concept Joel talks about in one of his essays: http://joelonsoftware.com/articles/Wrong.html

Ben Gartner
Thanks for the article, great insight!
Axsuul
A: 

From a C# or .NET perspective (but also Java but using camel case) I would choose:

  1. Clean() or Sanitize() is popular
  2. EncodeHtml() DecodeHtml()
Chris S