forked from CIT/Vmeda.Online
		
	MOBILE-3320 course: Fix regex patch matcher
This commit is contained in:
		
							parent
							
								
									ae74cdb91f
								
							
						
					
					
						commit
						81876ca518
					
				@ -17,7 +17,7 @@ import { UrlSegment, UrlSegmentGroup } from '@angular/router';
 | 
			
		||||
 | 
			
		||||
import { mock } from '@/testing/utils';
 | 
			
		||||
 | 
			
		||||
import { buildRegExpUrlMatcher } from '../app-routing.module';
 | 
			
		||||
import { buildRegExpUrlMatcher } from './app-routing.module';
 | 
			
		||||
 | 
			
		||||
describe('Routing utils', () => {
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,7 @@ describe('Routing utils', () => {
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
        testMatcher('baz/foo/bar', null);
 | 
			
		||||
        testMatcher('foobar', null);
 | 
			
		||||
        testMatcher('foo', ['foo']);
 | 
			
		||||
        testMatcher('foo/baz', ['foo']);
 | 
			
		||||
        testMatcher('foo/bar/bar/baz', ['foo', 'bar', 'bar']);
 | 
			
		||||
@ -113,14 +113,18 @@ export function buildRegExpUrlMatcher(regexp: RegExp): UrlMatcher {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Consume segments that match.
 | 
			
		||||
        const [consumed] = segments.slice(1).reduce(([consumed, path], segment) => path === match
 | 
			
		||||
            ? [consumed, path]
 | 
			
		||||
            :[
 | 
			
		||||
                consumed.concat(segment),
 | 
			
		||||
        const [consumedSegments, consumedPath] = segments.slice(1).reduce(([segments, path], segment) => path === match
 | 
			
		||||
            ? [segments, path]
 | 
			
		||||
            : [
 | 
			
		||||
                segments.concat(segment),
 | 
			
		||||
                `${path}/${segment.path}`,
 | 
			
		||||
            ], [[segments[0]] as UrlSegment[], segments[0].path]);
 | 
			
		||||
 | 
			
		||||
        return { consumed };
 | 
			
		||||
        if (consumedPath !== match) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return { consumed: consumedSegments };
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user