[wp-trac] [WordPress Trac] #19100: Introduce esc_color()
WordPress Trac
wp-trac at lists.automattic.com
Wed Nov 2 02:20:41 UTC 2011
#19100: Introduce esc_color()
------------------------------------+------------------------------
Reporter: mfields | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback |
------------------------------------+------------------------------
Changes (by mbijon):
* cc: mike@… (added)
Comment:
Surveying webhosts for ctype_ seems like overkill here.
Regex works for me. It can be a little slow but these strings should be
short and I don't think this will get used too many times in a loop. To
prevent super-long strings from causing slowdowns, we could also move the
length-check ahead of the character check:
{{{
if ( ! in_array( strlen( $color ), array( 3, 6 ) ) )
return $default;
if( function_exists( "ctype_xdigit" ) ) {
if ( ! ctype_xdigit( $color ) )
return $default;
} elseif ( ! preg_match( "/(([a-f0-9]){3}){1,2}$/i", $color ) ) {
return $default;
}
}}}
(Please check my regex syntax, I didn't try to break this enough)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19100#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list