Results 1 to 7 of 7

Thread: Ext.Router should handle trailing slashes

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78

    Default Ext.Router should handle trailing slashes

    I just spent a lot of time debugging my app because it wouldn't redirect to one of my custom routes. In the end I found that a simple trailing slash at the end of the url broke the whole route recognizer and the router just failed silently, which could be avoided with a simple fix.

    Code:
    createMatcherRegex: function(url) {
      var paramsInMatchString = this.paramsInMatchString,
        length = paramsInMatchString.length,
        i, cond, matcher;
      
      for (i = 0; i < length; i++) {
        cond = this.conditions[paramsInMatchString[i]];
        matcher = Ext.util.Format.format("({0})", cond || "[%a-zA-Z0-9\\_\\s,]+");
         
        url = url.replace(new RegExp(paramsInMatchString[i]), matcher);
      }
      
      return new RegExp("^" + url + "/?$");
    }
    cheers
    michael

  2. #2
    Sencha - Engineering Operations
    Join Date
    Mar 2011
    Location
    Redwood City, CA
    Posts
    221

    Default

    I've submitted this one to Engineering, thanks for reporting

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    8

    Question HOW to

    Hi Michael,
    thanks for this post, i've been struggling with the same problem.
    un fortunately i'm did'nt really grasped where to use this code: inside the router.js, or within the controller?
    Can you please provide some details on how to use this solution?
    Thanks a lot in advance
    Guido Serio

  4. #4
    Sencha User
    Join Date
    Jul 2010
    Location
    Switzerland
    Posts
    78

    Default

    You need to fix this directly in the sencha touch code, so it would be best to create an override for this method.

  5. #5
    Sencha User
    Join Date
    Sep 2010
    Posts
    8

    Default @mike Got it Thanks a lot!

    Thanks for reply man,
    have a great day!

  6. #6
    Sencha User edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939

    Default

    I don't think I agree with this. If the url has a trailing slash but the route is not set up to handle this, then it shouldn't match. If we start adding exceptions to this we'll be back next week when a route doesn't match a trailing question mark, or comma, or number or random letter.

    I'm going to mark this one as a won't fix for now.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  7. #7
    Sencha User edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939

    Default

    BTW if you do specify a trailing slash then this passes:

    Code:
    describe("a url with a trailing slash", function() {
        beforeEach(function() {
            route = Ext.create('Ext.app.Route', {
                url: ':controller/:action/'
            });
        });
        
        it("should match a url with a trailing slash", function() {
            expect(route.recognize('someController/someAction/')).toBeTruthy();
        });
    });
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •