/** * Ensures that setTagsAllowed() follows expected behavior when provided an array of tags * * @return void */ public function testSetTagsAllowedArray() { $tagsAllowed = array('b', 'a' => 'href', 'div' => array('id', 'class')); $this->_filter->setTagsAllowed($tagsAllowed); $tagsAllowedExpected = array('b' => array(), 'a' => array('href' => null), 'div' => array('id' => null, 'class' => null)); $this->assertEquals($tagsAllowedExpected, $this->_filter->getTagsAllowed()); }
/** * Returns string value of requested variable * * @param string $name variable name * @param bool $html allow html tags * @param string $default default value * @param string $method request method * @return string */ public static function string($name, $default = null, $html = false, $method = 'REQUEST') { self::init($name, $method); self::$val = isset(self::$request[self::$name]) ? self::$request[self::$name] : $default; $back = array(); if ($html == 1) { $val = self::$val; if (preg_match_all('/(<pre((?!>).)*>*)(((?!<\\/pre|<pre).)+)\\s*<\\/pre>/s', $val, $matches)) { self::createFilter(); $allowed = self::$filter->getTagsAllowed(); if (isset($allowed['pre'])) { foreach ($matches[3] as $i => $pre) { $id = '[%pre%]' . $i . '[%pre%]'; $back[$id] = array('content' => $pre, 'tag' => $matches[1][$i]); $val = str_replace($matches[1][$i] . $pre, $id, $val); } } } $val = self::filter($val); $conv = Sobi::Cfg('html.pre_to_entities', true); if (count($back)) { foreach ($back as $id => $pre) { if ($conv) { $pre['content'] = htmlentities($pre['content']); } $val = str_replace($id, $pre['tag'] . $pre['content'], $val); } } self::$val = $val; } elseif (!$html) { self::$val = strip_tags(self::$val); } return filter_var(self::$val, FILTER_SANITIZE_MAGIC_QUOTES); }