Implement better contextual escape for template v2

This commit is contained in:
Kijin Sung 2025-03-19 00:12:39 +09:00
parent baadb36e37
commit 9689a1ed68
2 changed files with 21 additions and 4 deletions

View file

@ -955,6 +955,23 @@ class Template
return UA::isMobile() && (config('mobile.tablets') || !UA::isTablet());
}
/**
* Contextual escape function for v2.
*
* @param string $str
* @param string $type
* @return string
*/
protected function _v2_escape(string $str, string $type = ''): string
{
switch ($this->config->context)
{
case 'CSS': return escape_css($str);
case 'JS': return escape_js($str);
default: return escape($str);
}
}
/**
* Lang shortcut for v2.
*