New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url dispatch: regexes with braces not currently accounted for and are not matched properly #123

Closed
nek4life opened this Issue Feb 9, 2011 · 3 comments

Comments

Projects
None yet
2 participants
@nek4life
Contributor

nek4life commented Feb 9, 2011

Example:

/{year:\d{4}}/ 

does not match /2002/ for instance.

Untested but ranges may not be accounted for either {m, n}

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Feb 9, 2011

Member
  • URL pattern markers used in URL dispatch are permitted to specify a custom
    regex. For example, the pattern /{foo:\d+} means to match /12345
    (foo==12345 in the match dictionary) but not /abc. However, custom
    regexes in a pattern marker which used squiggly brackets did not work. For
    example, /{foo:\d{4}} would fail to match /1234 and
    /{foo:\d{1,2}} would fail to match /1 or /11. One level of
    inner squiggly brackets is now recognized so that the prior two patterns
    given as examples now work. See also
    https://github.com/Pylons/pyramid/issues/#issue/123.

Closed by 9595236

Member

mcdonc commented Feb 9, 2011

  • URL pattern markers used in URL dispatch are permitted to specify a custom
    regex. For example, the pattern /{foo:\d+} means to match /12345
    (foo==12345 in the match dictionary) but not /abc. However, custom
    regexes in a pattern marker which used squiggly brackets did not work. For
    example, /{foo:\d{4}} would fail to match /1234 and
    /{foo:\d{1,2}} would fail to match /1 or /11. One level of
    inner squiggly brackets is now recognized so that the prior two patterns
    given as examples now work. See also
    https://github.com/Pylons/pyramid/issues/#issue/123.

Closed by 9595236

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Feb 17, 2011

Member

I have to reopen this, because the regex we used in commit #9594236 doesnt work on Jython. Here's the comment I put into the source code:

# The regex named ``torturous_route_re`` below allows us to support at least
# one level of "inner" squigglies inside the expr of a {name:expr} pattern;
# for example, {foo:\d{4}}.  Thanks to Zart for the regex help.
# ``torturous_route_re`` is meant to be a replacement for the regex named
# ``route_re`` (which is just (\{[a-zA-Z][^\}]*\})) because ``route_re``
# chokes when it encounters inner squigglies.  However
# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 means that the
# torturous regex doesn't work on Jython (recursion error), so we've disabled
# it in favor of ``route_re`` for now.  If somebody can make something that
# will work on Jython but also match inner squigglies, it'd be useful.

# torturous_route_re = re.compile(r'(\{[a-zA-Z](?:\{[^\}]*\}|[^\{\}]*)*\})')

route_re = re.compile(r'(\{[a-zA-Z][^\}]*\})')
Member

mcdonc commented Feb 17, 2011

I have to reopen this, because the regex we used in commit #9594236 doesnt work on Jython. Here's the comment I put into the source code:

# The regex named ``torturous_route_re`` below allows us to support at least
# one level of "inner" squigglies inside the expr of a {name:expr} pattern;
# for example, {foo:\d{4}}.  Thanks to Zart for the regex help.
# ``torturous_route_re`` is meant to be a replacement for the regex named
# ``route_re`` (which is just (\{[a-zA-Z][^\}]*\})) because ``route_re``
# chokes when it encounters inner squigglies.  However
# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 means that the
# torturous regex doesn't work on Jython (recursion error), so we've disabled
# it in favor of ``route_re`` for now.  If somebody can make something that
# will work on Jython but also match inner squigglies, it'd be useful.

# torturous_route_re = re.compile(r'(\{[a-zA-Z](?:\{[^\}]*\}|[^\{\}]*)*\})')

route_re = re.compile(r'(\{[a-zA-Z][^\}]*\})')
@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

mcdonc Apr 19, 2011

Member

This was fixed by @jgonera in his pull request at #176 ; it was merged to the trunk.

Member

mcdonc commented Apr 19, 2011

This was fixed by @jgonera in his pull request at #176 ; it was merged to the trunk.

@mcdonc mcdonc closed this Apr 19, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment