Nelmio\SecurityBundle\ContentSecurityPolicy\ShaComputer::computeForScript PHP Method

computeForScript() public method

public computeForScript ( $html )
    public function computeForScript($html)
    {
        if (1 !== preg_match_all('/<script[^>]*>/i', $html, $m)) {
            throw new \InvalidArgumentException('Invalid script, you should use a single <script> tag.');
        }
        preg_match('/^\\s*<script[^>]*>((?s).*)<\\/script>\\s*$/i', $html, $matches);
        if (!isset($matches[1])) {
            throw new \InvalidArgumentException('Invalid script, no <script> tag found.');
        }
        return $this->compute($matches[1]);
    }

Usage Example

 /**
  * @expectedException \InvalidArgumentException
  * @dataProvider provideInvalidScriptCode
  */
 public function testComputeScriptShouldFail($code)
 {
     $shaComputer = new ShaComputer('sha256');
     $shaComputer->computeForScript($code);
 }