1
1
/**
2
- * @license AngularJS v1.3.0-build.2711+sha.facd904
2
+ * @license AngularJS v1.2.26
3
3
* (c) 2010-2014 Google, Inc. http://angularjs.org
4
4
* License: MIT
5
5
*/
@@ -42,7 +42,7 @@ var $sanitizeMinErr = angular.$$minErr('$sanitize');
42
42
/**
43
43
* @ngdoc service
44
44
* @name $sanitize
45
- * @function
45
+ * @kind function
46
46
*
47
47
* @description
48
48
* The input is sanitized by parsing the html into tokens. All safe tokens (from a whitelist) are
@@ -57,20 +57,21 @@ var $sanitizeMinErr = angular.$$minErr('$sanitize');
57
57
* @returns {string } Sanitized html.
58
58
*
59
59
* @example
60
- <example module="ngSanitize " deps="angular-sanitize.js">
60
+ <example module="sanitizeExample " deps="angular-sanitize.js">
61
61
<file name="index.html">
62
62
<script>
63
- function Ctrl($scope, $sce) {
64
- $scope.snippet =
65
- '<p style="color:blue">an html\n' +
66
- '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
67
- 'snippet</p>';
68
- $scope.deliberatelyTrustDangerousSnippet = function() {
69
- return $sce.trustAsHtml($scope.snippet);
70
- };
71
- }
63
+ angular.module('sanitizeExample', ['ngSanitize'])
64
+ .controller('ExampleController', ['$scope', '$sce', function($scope, $sce) {
65
+ $scope.snippet =
66
+ '<p style="color:blue">an html\n' +
67
+ '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
68
+ 'snippet</p>';
69
+ $scope.deliberatelyTrustDangerousSnippet = function() {
70
+ return $sce.trustAsHtml($scope.snippet);
71
+ };
72
+ }]);
72
73
</script>
73
- <div ng-controller="Ctrl ">
74
+ <div ng-controller="ExampleController ">
74
75
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
75
76
<table>
76
77
<tr>
@@ -158,11 +159,11 @@ function sanitizeText(chars) {
158
159
159
160
// Regular Expressions for parsing tags and attributes
160
161
var START_TAG_REGEXP =
161
- / ^ < \s * ( [ \w : - ] + ) ( (?: \s + [ \w : - ] + (?: \s * = \s * (?: (?: " [ ^ " ] * " ) | (?: ' [ ^ ' ] * ' ) | [ ^ > \s ] + ) ) ? ) * ) \s * ( \/ ? ) \s * > / ,
162
- END_TAG_REGEXP = / ^ < \s * \ /\s * ( [ \w : - ] + ) [ ^ > ] * > / ,
162
+ / ^ < ( (?: [ a - z A - Z ] ) [ \w : - ] * ) ( (?: \s + [ \w : - ] + (?: \s * = \s * (?: (?: " [ ^ " ] * " ) | (?: ' [ ^ ' ] * ' ) | [ ^ > \s ] + ) ) ? ) * ) \s * ( \/ ? ) \s * ( > ? ) / ,
163
+ END_TAG_REGEXP = / ^ < \/ \s * ( [ \w : - ] + ) [ ^ > ] * > / ,
163
164
ATTR_REGEXP = / ( [ \w : - ] + ) (?: \s * = \s * (?: (?: " ( (?: [ ^ " ] ) * ) " ) | (?: ' ( (?: [ ^ ' ] ) * ) ' ) | ( [ ^ > \s ] + ) ) ) ? / g,
164
165
BEGIN_TAG_REGEXP = / ^ < / ,
165
- BEGING_END_TAGE_REGEXP = / ^ < \s * \ // ,
166
+ BEGING_END_TAGE_REGEXP = / ^ < \/ / ,
166
167
COMMENT_REGEXP = / < ! - - ( .* ?) - - > / g,
167
168
DOCTYPE_REGEXP = / < ! D O C T Y P E ( [ ^ > ] * ?) > / i,
168
169
CDATA_REGEXP = / < ! \[ C D A T A \[ ( .* ?) ] ] > / g,
@@ -236,10 +237,18 @@ function makeMap(str) {
236
237
* @param {object } handler
237
238
*/
238
239
function htmlParser ( html , handler ) {
239
- var index , chars , match , stack = [ ] , last = html ;
240
+ if ( typeof html !== 'string' ) {
241
+ if ( html === null || typeof html === 'undefined' ) {
242
+ html = '' ;
243
+ } else {
244
+ html = '' + html ;
245
+ }
246
+ }
247
+ var index , chars , match , stack = [ ] , last = html , text ;
240
248
stack . last = function ( ) { return stack [ stack . length - 1 ] ; } ;
241
249
242
250
while ( html ) {
251
+ text = '' ;
243
252
chars = true ;
244
253
245
254
// Make sure we're not in a script or style element
@@ -278,16 +287,23 @@ function htmlParser( html, handler ) {
278
287
match = html . match ( START_TAG_REGEXP ) ;
279
288
280
289
if ( match ) {
281
- html = html . substring ( match [ 0 ] . length ) ;
282
- match [ 0 ] . replace ( START_TAG_REGEXP , parseStartTag ) ;
290
+ // We only have a valid start-tag if there is a '>'.
291
+ if ( match [ 4 ] ) {
292
+ html = html . substring ( match [ 0 ] . length ) ;
293
+ match [ 0 ] . replace ( START_TAG_REGEXP , parseStartTag ) ;
294
+ }
283
295
chars = false ;
296
+ } else {
297
+ // no ending tag found --- this piece should be encoded as an entity.
298
+ text += '<' ;
299
+ html = html . substring ( 1 ) ;
284
300
}
285
301
}
286
302
287
303
if ( chars ) {
288
304
index = html . indexOf ( "<" ) ;
289
305
290
- var text = index < 0 ? html : html . substring ( 0 , index ) ;
306
+ text + = index < 0 ? html : html . substring ( 0 , index ) ;
291
307
html = index < 0 ? "" : html . substring ( index ) ;
292
308
293
309
if ( handler . chars ) handler . chars ( decodeEntities ( text ) ) ;
@@ -563,7 +579,7 @@ angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider);
563
579
/**
564
580
* @ngdoc filter
565
581
* @name linky
566
- * @function
582
+ * @kind function
567
583
*
568
584
* @description
569
585
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
@@ -579,20 +595,21 @@ angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider);
579
595
<span ng-bind-html="linky_expression | linky"></span>
580
596
*
581
597
* @example
582
- <example module="ngSanitize " deps="angular-sanitize.js">
598
+ <example module="linkyExample " deps="angular-sanitize.js">
583
599
<file name="index.html">
584
600
<script>
585
- function Ctrl($scope) {
586
- $scope.snippet =
587
- 'Pretty text with some links:\n'+
588
- 'http://angularjs.org/,\n'+
589
- 'mailto:us@somewhere .org,\n'+
590
- 'another@somewhere.org,\n'+
591
- 'and one more: ftp://127.0.0.1/.';
592
- $scope.snippetWithTarget = 'http://angularjs.org/';
593
- }
601
+ angular.module('linkyExample', ['ngSanitize'])
602
+ .controller('ExampleController', ['$scope', function($scope) {
603
+ $scope.snippet =
604
+ 'Pretty text with some links:\n'+
605
+ 'http://angularjs.org/,\n'+
606
+ 'mailto:us@somewhere .org,\n'+
607
+ 'another@somewhere.org,\n'+
608
+ 'and one more: ftp://127.0.0.1/.';
609
+ $scope.snippetWithTarget = 'http://angularjs.org/';
610
+ }]);
594
611
</script>
595
- <div ng-controller="Ctrl ">
612
+ <div ng-controller="ExampleController ">
596
613
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
597
614
<table>
598
615
<tr>
@@ -661,7 +678,7 @@ angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider);
661
678
*/
662
679
angular . module ( 'ngSanitize' ) . filter ( 'linky' , [ '$sanitize' , function ( $sanitize ) {
663
680
var LINKY_URL_REGEXP =
664
- / ( ( f t p | h t t p s ? ) : \/ \/ | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s . ; , ( ) { } < > ] / ,
681
+ / ( ( f t p | h t t p s ? ) : \/ \/ | ( m a i l t o : ) ? [ A - Z a - z 0 - 9 . _ % + - ] + @ ) \S * [ ^ \s . ; , ( ) { } < > " ] / ,
665
682
MAILTO_REGEXP = / ^ m a i l t o : / ;
666
683
667
684
return function ( text , target ) {
0 commit comments