public function testEscape() { $this->assertSame('htmlspecialchars($var, ENT_QUOTES | ENT_SUBSTITUTE, \'utf-8\')', trim(OutputWrapper::escape('$var'))); }
/** * Builds the variables for the current parts. * * @return string * @throws HtplException */ private function lexVariables() { $variables = []; do { $this->lexVariable(); $this->lexMathOperator(); $this->lexModifiers(); $variables[] = $this->currentVar; $this->currentVar = []; } while ($this->countParts() > 0); $varComplete = ''; foreach ($variables as $v) { foreach ($v as $type => $param) { // variable name if ($type == 'name') { $var = $this->outputParameter($param); } // modifiers if ($type == 'modifiers') { // pre-escape if (isset($param['pre-escape'])) { foreach ($param['pre-escape'] as $mod) { $var = $this->outputModifier($mod, $var); } } // escape $var = OutputWrapper::escape($var); // post-escape if (isset($param['post-escape'])) { foreach ($param['post-escape'] as $mod) { $var = $this->outputModifier($mod, $var); } } } // math operations if ($type == 'mathOperators') { foreach ($param as $operator) { $var .= $operator; } } } $varComplete .= isset($v['modifiers']) ? $var : OutputWrapper::escape($var); } return $varComplete; }