11/**
22 * State-based routing for AngularJS
3- * @version v0.3.2
3+ * @version v0.4.0
44 * @link http://angular-ui.github.com/
55 * @license MIT License, http://www.opensource.org/licenses/MIT
66 */
@@ -563,6 +563,57 @@ function $Resolve( $q, $injector) {
563563angular . module ( 'ui.router.util' ) . service ( '$resolve' , $Resolve ) ;
564564
565565
566+
567+ /**
568+ * @ngdoc object
569+ * @name ui.router.util.$templateFactoryProvider
570+ *
571+ * @description
572+ * Provider for $templateFactory. Manages which template-loading mechanism to
573+ * use, and will default to the most recent one ($templateRequest on Angular
574+ * versions starting from 1.3, $http otherwise).
575+ */
576+ function TemplateFactoryProvider ( ) {
577+ var shouldUnsafelyUseHttp = angular . version . minor < 3 ;
578+
579+ /**
580+ * @ngdoc function
581+ * @name ui.router.util.$templateFactoryProvider#shouldUnsafelyUseHttp
582+ * @methodOf ui.router.util.$templateFactoryProvider
583+ *
584+ * @description
585+ * Forces $templateFactory to use $http instead of $templateRequest. This
586+ * might cause XSS, as $http doesn't enforce the regular security checks for
587+ * templates that have been introduced in Angular 1.3. Note that setting this
588+ * to false on Angular older than 1.3.x will crash, as the $templateRequest
589+ * service (and the security checks) are not implemented on these versions.
590+ *
591+ * See the $sce documentation, section
592+ * <a href="https://docs.angularjs.org/api/ng/service/$sce#impact-on-loading-templates">
593+ * Impact on loading templates</a> for more details about this mechanism.
594+ *
595+ * @param {boolean } value
596+ */
597+ this . shouldUnsafelyUseHttp = function ( value ) {
598+ shouldUnsafelyUseHttp = ! ! value ;
599+ } ;
600+
601+ /**
602+ * @ngdoc object
603+ * @name ui.router.util.$templateFactory
604+ *
605+ * @requires $http
606+ * @requires $templateCache
607+ * @requires $injector
608+ *
609+ * @description
610+ * Service. Manages loading of templates.
611+ */
612+ this . $get = [ '$http' , '$templateCache' , '$injector' , function ( $http , $templateCache , $injector ) {
613+ return new TemplateFactory ( $http , $templateCache , $injector , shouldUnsafelyUseHttp ) ; } ] ;
614+ }
615+
616+
566617/**
567618 * @ngdoc object
568619 * @name ui.router.util.$templateFactory
@@ -574,8 +625,7 @@ angular.module('ui.router.util').service('$resolve', $Resolve);
574625 * @description
575626 * Service. Manages loading of templates.
576627 */
577- $TemplateFactory . $inject = [ '$http' , '$templateCache' , '$injector' ] ;
578- function $TemplateFactory ( $http , $templateCache , $injector ) {
628+ function TemplateFactory ( $http , $templateCache , $injector , shouldUnsafelyUseHttp ) {
579629
580630 /**
581631 * @ngdoc function
@@ -647,9 +697,15 @@ function $TemplateFactory( $http, $templateCache, $injector) {
647697 this . fromUrl = function ( url , params ) {
648698 if ( isFunction ( url ) ) url = url ( params ) ;
649699 if ( url == null ) return null ;
650- else return $http
651- . get ( url , { cache : $templateCache , headers : { Accept : 'text/html' } } )
652- . then ( function ( response ) { return response . data ; } ) ;
700+ else {
701+ if ( ! shouldUnsafelyUseHttp ) {
702+ return $injector . get ( '$templateRequest' ) ( url ) ;
703+ } else {
704+ return $http
705+ . get ( url , { cache : $templateCache , headers : { Accept : 'text/html' } } )
706+ . then ( function ( response ) { return response . data ; } ) ;
707+ }
708+ }
653709 } ;
654710
655711 /**
@@ -672,7 +728,7 @@ function $TemplateFactory( $http, $templateCache, $injector) {
672728 } ;
673729}
674730
675- angular . module ( 'ui.router.util' ) . service ( '$templateFactory' , $TemplateFactory ) ;
731+ angular . module ( 'ui.router.util' ) . provider ( '$templateFactory' , TemplateFactoryProvider ) ;
676732
677733var $$UMFP ; // reference to $UrlMatcherFactoryProvider
678734
@@ -1286,7 +1342,7 @@ function $UrlMatcherFactory() {
12861342 "int" : {
12871343 encode : valToString ,
12881344 decode : function ( val ) { return parseInt ( val , 10 ) ; } ,
1289- is : function ( val ) { return isDefined ( val ) && this . decode ( val . toString ( ) ) === val ; } ,
1345+ is : function ( val ) { return val !== undefined && val !== null && this . decode ( val . toString ( ) ) === val ; } ,
12901346 pattern : / \d + /
12911347 } ,
12921348 "bool" : {
@@ -3409,6 +3465,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
34093465 return $q . reject ( error ) ;
34103466 } ) ;
34113467
3468+ transition . catch ( angular . noop ) ;
34123469 return transition ;
34133470 } ;
34143471
@@ -3452,7 +3509,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
34523509
34533510 if ( ! isDefined ( state ) ) { return undefined ; }
34543511 if ( $state . $current !== state ) { return false ; }
3455- return params ? equalForKeys ( state . params . $$values ( params ) , $stateParams ) : true ;
3512+
3513+ return ! params || objectKeys ( params ) . reduce ( function ( acc , key ) {
3514+ var paramDef = state . params [ key ] ;
3515+ return acc && ! paramDef || paramDef . type . equals ( $stateParams [ key ] , params [ key ] ) ;
3516+ } , true ) ;
34563517 } ;
34573518
34583519 /**
@@ -3528,7 +3589,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
35283589 }
35293590 }
35303591
3531- return true ;
3592+ return objectKeys ( params ) . reduce ( function ( acc , key ) {
3593+ var paramDef = state . params [ key ] ;
3594+ return acc && ! paramDef || paramDef . type . equals ( $stateParams [ key ] , params [ key ] ) ;
3595+ } , true ) ;
35323596 } ;
35333597
35343598
@@ -4105,12 +4169,21 @@ function $ViewDirectiveFill ( $compile, $controller, $state, $interpolate
41054169 priority : - 400 ,
41064170 compile : function ( tElement ) {
41074171 var initial = tElement . html ( ) ;
4172+ if ( tElement . empty ) {
4173+ tElement . empty ( ) ;
4174+ } else {
4175+ // ng 1.0.0 doesn't have empty(), which cleans up data and handlers
4176+ tElement [ 0 ] . innerHTML = null ;
4177+ }
4178+
41084179 return function ( scope , $element , attrs ) {
41094180 var current = $state . $current ,
41104181 name = getUiViewName ( scope , attrs , $element , $interpolate ) ,
41114182 locals = current && current . locals [ name ] ;
41124183
41134184 if ( ! locals ) {
4185+ $element . html ( initial ) ;
4186+ $compile ( $element . contents ( ) ) ( scope ) ;
41144187 return ;
41154188 }
41164189
0 commit comments