Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2248 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

tg.url() behaves differently than pylons.url()

Reported by: Federico2 Owned by:
Priority: high Milestone: 2.1a1
Component: TurboGears Version: 2.1
Severity: normal Keywords: tg.url pylons.url


tg.url() is not

The following items in a Genshi template:

        <a href="${tg.url('')}">link1</a>
        <a href="${tg.url(['where','wolf'])}">link2</a>
        <a href="${tg.url('',action='update')}">link3</a>
        <a href="${tg.url('')}/update">link4</a>
        <a href="${tg.url('') + '/update'}">link5</a>

Will generate:

        <a href="">link1</a>
        <a href="where/wolf">link2</a>
        <a href="?action=update">link3</a>
        <a href="/update">link4</a>
        <a href="/update">link5</a>

While ${tg.url()} and ${tg.url(action='update')} will return:

 IndexError: list index out of range
>>  ${tg.url()}
Module tg.controllers:737 in url         view
<<      """
        args = list(args)
        if isinstance(args[0], list):
            args[0] = u'/'.join(args[0])
        if args and isinstance(args[0], basestring):
>>  if isinstance(args[0], list):

I'm running this code inside a subcontroller but I never get the absolute URL.

Change History

comment:1 follow-up: ↓ 2 Changed 10 years ago by jorge.vargas

Here is my take on what this api should be.

tg.url() -> current path
tg.url('') -> ?
tg.url('/') -> /
tg.url('/something') -> /something
tg.url(list) -> /elem1/elem2/....
tg.url('',some=thing) -> ?some=thing
tg.url('',some=thing,other=thing) -> ?some=thing&other=thing
tg.url('/p',some=thing) -> /p?some=thing
tg.url('p',some=thing,other=thing) -> p?some=thing&other=thing
tg.url(action='update') -> routes

Does that makes sense? will it please everyone?

comment:2 in reply to: ↑ 1 Changed 10 years ago by Rich43

Also, My controllers feed in unicode data from POST and GET, I usually feed some of that straight out to the url function in my template. Because of that I have to wrap str() around my code to make it safe.

I heard unicode is unsecure yet it does not convert to a plain string.

comment:3 follow-up: ↓ 4 Changed 10 years ago by Rich43

Sorry, I mean url() lacks unicode support.

comment:4 in reply to: ↑ 3 Changed 10 years ago by jorge.vargas

  • Milestone changed from 2.0 to 2.0rc1

Replying to Rich43:

Sorry, I mean url() lacks unicode support.

This was supposedly fixed in b3

comment:5 Changed 10 years ago by mramm

  • Priority changed from normal to high

comment:6 Changed 10 years ago by percious

This is fixed in 2.1 and I think it should be closed. TGController is inherently differnt from WSGIController and therefore the functionality should be expected to be different.

comment:7 Changed 10 years ago by mramm

  • Milestone changed from 2.0rc2 to 2.1

We spent a good amount of time fixing this at the pycon sprints, but it's too big of a change to do before 2.1.

comment:8 Changed 10 years ago by percious

  • Version changed from 2.0b5 to 2.1
  • Milestone changed from 2.1 to 2.1a1

comment:9 Changed 10 years ago by percious

i think this is complete for 2.1. Perhaps we need to add some tests to verify that it is indeed fixed. I think we have pretty good test coverage in this area however.

comment:10 Changed 10 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed

Im closing this ticket because I believe this is fixed. Please feel free to re-open, providing a test-case to the contrary.

Note: See TracTickets for help on using tickets.