Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Do you whitelist or blacklist utf-8? [SOLVED]



TLUG,

Thanks to everyone for the advice.

I think I've got to a place where I'm comfortable I'm filtering the
right things.

There might be some evolution in how I handle things, but the essential
issue of whitelisting and blacklisting characters seems to be resolved.

If anyone notices any problems with what I'm doing, by all means please
tell me.

In PHP:

function hasNoBlacklistedCharacters($string)
{
   // Return TRUE to say "no blacklisted characters".
   // Death to unwanted spacing characters!
   return !preg_match('/[\t\n\r\a\e\f\v]/', $string);
}

function hasOnlyWhitelistedCharacters($string)
{
    // return TRUE to say "only whitelisted characters"
    return preg_match('/^[\p{L}\p{N}\p{Z}.@example.com/u', $string);
}

In Javascript:

function hasOnlyWhitelistedCharacters(string)
{
   // Seems to whitelist utf-8 character ranges even
   // though Javascript doesn't do nice utf-8 support
   // like PHP does.
   var whitelist = /^[\w \u00C0-\uDFFF\uF900-\uFFFF]*$/;
  return whitelist.test(string);
}
function hasNoBlacklistedChars(string)
{
   // Death to evil spaces!
   var blacklist = /[\t\n\r\a\e\f\v]/';
   return ! blacklist.test(string);
}

-- 
Dave M G



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links