ngSanitize : badparse for <style> <!--\n--> </style> gives bad parse error angularjs

329 Views Asked by At

I get a badparse error trying to sanitize

<style> <!--\n--> </style> gives bad parse error angularjs. I use ngSanitize in my module to sanitize. I am able to parse most HTML content well but this fails.

Is there a special reason why this string fails?

TIA

1

There are 1 best solutions below

4
On

angular.module('app', ['ngSanitize'])
.controller('ctrl', ['$scope', '$sce', function($scope, $sce) {     
    $scope.style = $sce.trustAsHtml(
   `<script>
      alert("Some bad");
    <\/script>
    <style>
        .green{
            background-color:green
        }
    </style>`);      
}])
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-sanitize.min.js"></script>

<div ng-app='app' ng-controller="ctrl">
    <div ng-bind-html='style'></div>
    <div class='green'>Green</div>    
</div>