@ 2014-07-13T11:46:07Z <?php
define("TYPE_HTML_TEXT",1);
define("TYPE_NUMBER", 2);
define("TYPE_BOOLEAN", 3);
define("TYPE_SCRIPT", 4);
define("TYPE_BINARY", 5);
define("TYPE_URL", 6);
define("TYPE_LIST_ITEM", 7);
define("TYPE_LIST", 8);
define("TYPE_COLOR", 9);
define("TYPE_CSS_ATTR", 10);
define("TYPE_CSS_ATTR_COLOR", 11);
define("TYPE_CSS_ATTR_SIZE", 12);
define("TYPE_CSS_CUSTOM", 13);
define("TYPE_SIZE", 14);
define("TYPE_CDATA", 15);
define("TYPE_CONFIG", 16);
define("TYPE_HTML_MARKUP", 17);
/**
* ord() alternative that works with UTF8 characters
* @param string $c
*
* @return int UTF-8 character code value
*/
function getUTF8CharCode($c) {
$h = ord($c{0});
if ($h <= 0x7F) {
return $h;
} else if ($h < 0xC2) {
return false;
} else if ($h <= 0xDF) {
return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
} else if ($h <= 0xEF) {
return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
| (ord($c{2}) & 0x3F);
} else if ($h <= 0xF4) {
return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
| (ord($c{2}) & 0x3F) << 6
| (ord($c{3}) & 0x3F);
} else {
return -1;
}
}
/**
* Escape a single character for CSS context.
* @param $c
* @return string
*/
function escapeCSSCharacter($c) {
return "\\" . base_convert(getUTF8CharCode($c), 10, 16) . " ";
}
/**
* Escape CSS rule
*
* @param string $data The CSS rule
* @param array $immuneChars Array of immune character. These characters will not be escaped.
*
* @return string Escaped string
*/
function escapeCSSValue($data, array $immuneChars = array()) {
$result = "";
for ($i = 0; $i < mb_strlen($data); $i++) {
$currChar = mb_substr($data, $i, 1);
if (getUTF8CharCode($currChar) < 256 && //Character with ASCII value of 255 or less are dangerous!
!preg_match("/^\w$/", $currChar) && //Alphanumeric and underscores are safe.
!in_array($currChar, $immuneChars) //Immune characters are safe.
) {
$result .= escapeCSSCharacter($currChar);
}
else {
$result .= $currChar;
}
}
return $result;
}
function encodeJSONProperty($type, $value, $raw = false) {
global $ESCAPE_PROPERTIES;
if ($raw || !$ESCAPE_PROPERTIES) { //$raw == true means to explicitly not escape.
//$ESCAPE_PROPERTIES is the feature flag. True means we want escaping.
return $value;
}
switch ($type) {
case TYPE_HTML_TEXT:
return htmlspecialchars($value);
case TYPE_CONFIG:
case TYPE_LIST_ITEM:
case TYPE_LIST:
case TYPE_HTML_MARKUP:
return $value;
case TYPE_NUMBER:
return (int)$value;
case TYPE_BOOLEAN:
return stristr($value, "true") != false;
case TYPE_SCRIPT:
return new JSONFunction($value);
case TYPE_URL:
return urlencode($value);
case TYPE_COLOR:
case TYPE_SIZE:
return escapeCSSValue($value, array("#", ",", ".", "(", ")", "-", "%", "*", "+", "=", "/"));
}
}
echo encodeJSONProperty(TYPE_HTML_TEXT, "<script src="evil.js">Evil</script>");
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.30 0.008 0.049 12.55 5.4.29 0.007 0.042 12.54 5.4.28 0.006 0.041 12.44 5.4.27 0.004 0.041 12.44 5.4.26 0.009 0.037 12.44 5.4.25 0.009 0.041 12.44 5.4.24 0.008 0.039 12.44 5.4.23 0.011 0.039 12.43 5.4.22 0.008 0.037 12.43 5.4.21 0.008 0.037 12.43 5.4.20 0.007 0.042 12.43 5.4.19 0.006 0.038 12.43 5.4.18 0.006 0.039 12.42 5.4.17 0.006 0.039 12.43 5.4.16 0.010 0.039 12.43 5.4.15 0.007 0.037 12.42 5.4.14 0.005 0.040 12.11 5.4.13 0.006 0.037 12.09 5.4.12 0.008 0.037 12.05 5.4.11 0.007 0.037 12.05 5.4.10 0.012 0.034 12.06 5.4.9 0.009 0.039 12.05 5.4.8 0.009 0.039 12.05 5.4.7 0.009 0.045 12.05 5.4.6 0.008 0.035 12.05 5.4.5 0.007 0.039 12.05 5.4.4 0.004 0.043 12.04 5.4.3 0.007 0.047 12.03 5.4.2 0.007 0.053 12.03 5.4.1 0.007 0.051 12.04 5.4.0 0.013 0.054 11.53 5.3.28 0.009 0.055 12.72 5.3.27 0.011 0.056 12.73 5.3.26 0.010 0.057 12.72 5.3.25 0.006 0.040 12.73 5.3.24 0.006 0.040 12.73 5.3.23 0.010 0.038 12.72 5.3.22 0.007 0.039 12.69 5.3.21 0.007 0.041 12.69 5.3.20 0.007 0.046 12.69 5.3.19 0.011 0.045 12.69 5.3.18 0.007 0.049 12.68 5.3.17 0.007 0.049 12.68 5.3.16 0.013 0.044 12.68 5.3.15 0.020 0.038 12.68 5.3.14 0.007 0.052 12.67 5.3.13 0.015 0.048 12.67 5.3.12 0.008 0.052 12.67 5.3.11 0.014 0.046 12.67 5.3.10 0.009 0.048 12.15 5.3.9 0.009 0.050 12.14 5.3.8 0.010 0.040 12.13 5.3.7 0.010 0.046 12.13 5.3.6 0.012 0.043 12.11 5.3.5 0.012 0.044 12.06 5.3.4 0.008 0.064 12.06 5.3.3 0.007 0.054 12.03 5.3.2 0.008 0.054 11.80 5.3.1 0.007 0.054 11.76 5.3.0 0.006 0.056 11.75
preferences:dark mode live preview
157.2 ms | 1394 KiB | 7 Q