File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -449,13 +449,22 @@ function $UrlMatcherFactory() {
449
449
* @methodOf ui.router.util.$urlMatcherFactory
450
450
*
451
451
* @description
452
- * Returns true if the specified object is a UrlMatcher, or false otherwise.
452
+ * Returns true if the specified object is a ` UrlMatcher` , or false otherwise.
453
453
*
454
454
* @param {Object } object The object to perform the type check against.
455
- * @returns {Boolean } Returns `true` if the object has the following functions: `exec`, `format`, and `concat`.
455
+ * @returns {Boolean } Returns `true` if the object matches the `UrlMatcher` interface, by
456
+ * implementing all the same methods.
456
457
*/
457
458
this . isMatcher = function ( o ) {
458
- return isObject ( o ) && isFunction ( o . exec ) && isFunction ( o . format ) && isFunction ( o . concat ) ;
459
+ if ( ! isObject ( o ) ) return false ;
460
+ var result = true ;
461
+
462
+ forEach ( UrlMatcher . prototype , function ( val , name ) {
463
+ if ( isFunction ( val ) ) {
464
+ result = result && ( isDefined ( o [ name ] ) && isFunction ( o [ name ] ) ) ;
465
+ }
466
+ } ) ;
467
+ return result ;
459
468
} ;
460
469
461
470
this . type = function ( name , def ) {
Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ describe("UrlMatcher", function () {
29
29
provider . strictMode ( false ) ;
30
30
expect ( provider . compile ( '/hello' ) . exec ( '/hello/' ) ) . toEqual ( { } ) ;
31
31
} ) ;
32
+
33
+ it ( "should correctly validate UrlMatcher interface" , function ( ) {
34
+ var m = new UrlMatcher ( "/" ) ;
35
+ expect ( provider . isMatcher ( m ) ) . toBe ( true ) ;
36
+
37
+ m . validates = null ;
38
+ expect ( provider . isMatcher ( m ) ) . toBe ( false ) ;
39
+ } ) ;
32
40
} ) ;
33
41
34
42
it ( "should match static URLs" , function ( ) {
@@ -177,7 +185,13 @@ describe("urlMatcherFactory", function () {
177
185
it ( "recognizes matchers" , function ( ) {
178
186
expect ( $umf . isMatcher ( new UrlMatcher ( '/' ) ) ) . toBe ( true ) ;
179
187
180
- var custom = { format : angular . noop , exec : angular . noop , concat : angular . noop } ;
188
+ var custom = {
189
+ format : angular . noop ,
190
+ exec : angular . noop ,
191
+ concat : angular . noop ,
192
+ validates : angular . noop ,
193
+ parameters : angular . noop
194
+ } ;
181
195
expect ( $umf . isMatcher ( custom ) ) . toBe ( true ) ;
182
196
} ) ;
183
197
You can’t perform that action at this time.
0 commit comments