public static function escape($string, $arrayGlue = ' ') { if ($string instanceof SafeHtml) { return $string; } else { if ($string instanceof ISafeHtmlProducer) { $result = $string->produceSafeHTML(); if ($result instanceof SafeHtml) { return $result; } else { if (is_array($result)) { return self::escape($result, $arrayGlue); } else { if ($result instanceof ISafeHtmlProducer) { return self::escape($result, $arrayGlue); } else { try { Strings::stringable($result); return self::escape((string) $result); } catch (\Exception $ex) { $class = get_class($string); throw new \Exception("Object (of class '{$class}') implements " . "ISafeHTMLProducer but did not return anything " . "renderable from produceSafeHTML()."); } } } } } else { if (is_array($string)) { return implode($arrayGlue, array_map(['\\Packaged\\Glimpse\\Core\\SafeHtml', 'escape'], $string)); } } } return Strings::escape($string); }
/** * Escape HTML String * * @param $string * * @return string * * @deprecated */ function esc($string) { return \Packaged\Helpers\Strings::escape($string); }
public function renderTextarea(FormElement $element) { $out = '<textarea'; $out .= $this->_renderAttributes($element); $out .= '>'; $out .= Strings::escape($element->getValue()); $out .= '</textarea>'; return $out; }
public function testEscape() { $expectations = [['Strings', "Strings"], ['Stri"ngs', "Stri"ngs"], ['Stri\'ngs', "Stri'ngs"]]; foreach ($expectations as $expect) { $this->assertEquals($expect[1], Strings::escape($expect[0])); } }