crossroads.js icon indicating copy to clipboard operation
crossroads.js copied to clipboard

Multiple optional Parameters

Open TobiasOetzel opened this issue 10 years ago • 1 comments

Hi,

if you define a pattern with 3 optional parameters and you supply the 1st and the 3rd the order is mixed up. eg : /:lorem:/:ipsum:/:dolor: matched against /lorem//dolor will map lorem to lorem, ipsum to dolor and dolor to undefined.

i would expect ipsum to be undefined and dolor to be dolor. Although using a :?parameter: would make more sense if you have 3 optional ones.

i wrote a test in the lexer.spec.js that fails:

    it('should return optional pattern params', function(){
        var pattern = '/:lorem:/:ipsum:/:dolor:',
            regex = crossroads.patternLexer.compilePattern(pattern),
            params = crossroads.patternLexer.getParamValues('/lorem//dolor', regex);

        expect( params[0] ).toEqual( 'lorem' );
        expect( params[1] ).toEqual( undefined );
        expect( params[2] ).toEqual( 'dolor' );
    });

but i did not come up with a fix yet.

Best regards, Tobias

TobiasOetzel avatar Oct 08 '14 12:10 TobiasOetzel

Not sure how this is going to be handled here, but on every other routing framework I've seen out there, any optional path parameters were only allowed in the end of the URL.

corintho avatar Apr 10 '15 01:04 corintho