You are here

public function Twig_Test_EscapingTest::testJavascriptEscapingEscapesOwaspRecommendedRanges in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/test/Twig/Tests/escapingTest.php \Twig_Test_EscapingTest::testJavascriptEscapingEscapesOwaspRecommendedRanges()

File

vendor/twig/twig/test/Twig/Tests/escapingTest.php, line 256

Class

Twig_Test_EscapingTest
This class is adapted from code coming from Zend Framework.

Code

public function testJavascriptEscapingEscapesOwaspRecommendedRanges() {
  $immune = array(
    ',',
    '.',
    '_',
  );

  // Exceptions to escaping ranges
  for ($chr = 0; $chr < 0xff; ++$chr) {
    if ($chr >= 0x30 && $chr <= 0x39 || $chr >= 0x41 && $chr <= 0x5a || $chr >= 0x61 && $chr <= 0x7a) {
      $literal = $this
        ->codepointToUtf8($chr);
      $this
        ->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js'));
    }
    else {
      $literal = $this
        ->codepointToUtf8($chr);
      if (in_array($literal, $immune)) {
        $this
          ->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js'));
      }
      else {
        $this
          ->assertNotEquals($literal, twig_escape_filter($this->env, $literal, 'js'), "{$literal} should be escaped!");
      }
    }
  }
}