[web2py] Bug in URL(..,..,vars={})

40 views
Skip to first unread message

Phyo Arkar

unread,
Aug 19, 2010, 2:39:55 PM8/19/10
to web2py
Trunk version Rev 853

in view:
$("#list").jqGrid({
    url:"{{=URL(r=request,f='listMIME.json',vars={'extracted_path':extracted_path,'source_path':source_path})}}",

HTML Result:
    $("#list").jqGrid({
    url:"/sExtract/extraction/listMIME.json?source_path=home&extracted_path=target",

it insert  &instead of &

that screwed up all my sites :D ..

have not tested with released version ..

Alexandre Andrade

unread,
Aug 19, 2010, 3:07:07 PM8/19/10
to web...@googlegroups.com
I really don't know how it works with json, but the sintaxe for URL haven't 'vars' but args=['a','b','etc']



2010/8/19 Phyo Arkar <phyo.ar...@gmail.com>



--
Atenciosamente

--
=========================
Alexandre Andrade
Hipercenter.com

Phyo Arkar

unread,
Aug 19, 2010, 3:45:42 PM8/19/10
to web...@googlegroups.com
Nothing related to Json, web2py html template works everywhere inside views.

From Doc :



        >>> URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
        ...     vars={'p':1, 'q':2}, anchor='1')
        '/a/c/f/x/y/z#1?q=2&p=1'

    generates a url \"/a/c/f\" corresponding to application a, controller c
    and function f. If r=request is passed, a, c, f are set, respectively,
    to r.application, r.controller, r.function.

mdipierro

unread,
Aug 19, 2010, 4:16:18 PM8/19/10
to web2py-users
I think it is a bug introduced with the new URL. I will check and fix
it tonight.

On Aug 19, 2:45 pm, Phyo Arkar <phyo.arkarl...@gmail.com> wrote:
> Nothing related to Json, web2py html template works everywhere inside views.
>
> From Doc :
>
>         >>> URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
>         ...     *vars={'p':1, 'q':2}*, anchor='1')
>         '/a/c/f/x/y/z#1?q=2&p=1'
>
>     generates a url \"/a/c/f\" corresponding to application a, controller c
>     and function f. If r=request is passed, a, c, f are set, respectively,
>     to r.application, r.controller, r.function.
>
> On Fri, Aug 20, 2010 at 1:37 AM, Alexandre Andrade <alexandrema...@gmail.com
>
> > wrote:
> > I really don't know how it works with json, but the sintaxe for URL haven't
> > 'vars' but args=['a','b','etc']
>
> > 2010/8/19 Phyo Arkar <phyo.arkarl...@gmail.com>
>
> > Trunk version Rev 853
>
> >> in view:
> >> $("#list").jqGrid({
>
> >> url:"{{=URL(r=request,f='listMIME.json',vars={'extracted_path':extracted_path,'source_path':source_path})}}",
>
> >> HTML Result:
> >>     $("#list").jqGrid({
> >>     url:"/sExtract/extraction/listMIME.json?source_path=home*&amp*

mdipierro

unread,
Aug 19, 2010, 9:38:40 PM8/19/10
to web2py-users
There is a problem (in 1.83.2 and earlier version)

URL(....)

returns a string, not a helper. If you want to include the string
without escaping twice you have to do

{{=XML(URL(...))}}

In trunk, I modified the definition of URL so that it returns the
XML(..) helper wrapping the string. This will prevent

{{=URL(...)}}

from double escaping but will prevent you from doing

'http://127.0.0.:8000'+URL(..)

you would have to do

'http://127.0.0.:8000%s' % URL(..)

we cannot have it both ways.

URL is either a helper or a string... The more I think about it the
more I am convinced URL should be a helper not a string otherwise all
the examples in which we use {{=URL(...)}} are buggy. Therefore this
change should be considered a bug fix and not a breaking of backward
compatibility.

What do other people think? Should we change this as in trunk or leave
it alone?

Massimo










On Aug 19, 1:39 pm, Phyo Arkar <phyo.arkarl...@gmail.com> wrote:
> Trunk version Rev 853
>
> in view:
> $("#list").jqGrid({
>
> url:"{{=URL(r=request,f='listMIME.json',vars={'extracted_path':extracted_path,'source_path':source_path})}}",
>
> HTML Result:
>     $("#list").jqGrid({
>     url:"/sExtract/extraction/listMIME.json?source_path=home*&amp*

mdipierro

unread,
Aug 19, 2010, 9:58:56 PM8/19/10
to web2py-users
On a second thought we should leave it alone. Else we break the
scaffolding app, i.e. 90% os apps out there.. Anyway,... I'd still
like to hear your opinions.

Phyo Arkar

unread,
Aug 20, 2010, 9:23:54 AM8/20/10
to web...@googlegroups.com
So the way it worked before was a bug and now (rev 853) it is a feature?

mdipierro

unread,
Aug 20, 2010, 11:29:08 AM8/20/10
to web2py-users
I changed and changed back. I am waiting for comments form other
developers. I am not sure what the best course of action is.

Massimo

On Aug 20, 8:23 am, Phyo Arkar <phyo.arkarl...@gmail.com> wrote:
> So the way it worked before was a bug and now (rev 853) it is a feature?
>

Jonathan Lundell

unread,
Aug 20, 2010, 12:09:16 PM8/20/10
to web...@googlegroups.com
On Aug 20, 2010, at 8:29 AM, mdipierro wrote:

> I changed and changed back. I am waiting for comments form other
> developers. I am not sure what the best course of action is.

What's an example of the framework breakage using the helper form of URL?

Jonathan Lundell

unread,
Aug 20, 2010, 12:22:13 PM8/20/10
to web...@googlegroups.com
On Aug 19, 2010, at 6:38 PM, mdipierro wrote:

> In trunk, I modified the definition of URL so that it returns the
> XML(..) helper wrapping the string. This will prevent
>
> {{=URL(...)}}
>
> from double escaping but will prevent you from doing
>
> 'http://127.0.0.:8000'+URL(..)

Couldn't this be fixed by implementing URL.__radd__() ?

def __add__(self,other):
return '%s%s' % (self,other)

def __radd__(self,other):
return '%s%s' % (other,self)

Jonathan Lundell

unread,
Aug 20, 2010, 12:31:49 PM8/20/10
to web...@googlegroups.com
On Aug 20, 2010, at 9:22 AM, Jonathan Lundell wrote:

> On Aug 19, 2010, at 6:38 PM, mdipierro wrote:
>
>> In trunk, I modified the definition of URL so that it returns the
>> XML(..) helper wrapping the string. This will prevent
>>
>> {{=URL(...)}}
>>
>> from double escaping but will prevent you from doing
>>
>> 'http://127.0.0.:8000'+URL(..)
>
> Couldn't this be fixed by implementing URL.__radd__() ?

I meant XML.__radd__()

mdipierro

unread,
Aug 20, 2010, 1:17:43 PM8/20/10
to web2py-users
I did as you suggest. I also had to add lower(), upper() and __len__
methods to the XML class.
I think this is a good solution. Thanks Jonathan.

Massimo

Jonathan Lundell

unread,
Aug 20, 2010, 1:25:06 PM8/20/10
to web...@googlegroups.com
On Aug 20, 2010, at 10:17 AM, mdipierro wrote:

> I did as you suggest. I also had to add lower(), upper() and __len__
> methods to the XML class.
> I think this is a good solution. Thanks Jonathan.

oops:

+ def upper(self):
+ return str(self).lower()

mdipierro

unread,
Aug 20, 2010, 2:50:25 PM8/20/10
to web2py-users
fixed. ;-)

Phyo Arkar

unread,
Aug 20, 2010, 4:47:15 PM8/20/10
to web...@googlegroups.com
cool

so =XML(=URL(,,,)) is the way to go?

mdipierro

unread,
Aug 20, 2010, 5:24:44 PM8/20/10
to web2py-users
With stable {{=XML(URL(...))}}.
With the last trunk {{=URL(...)}}.

If no major objection this new trunk feature will become stable.

On Aug 20, 3:47 pm, Phyo Arkar <phyo.arkarl...@gmail.com> wrote:
> cool
>
> so =XML(=URL(,,,)) is the way to go?
>

Iceberg

unread,
Sep 30, 2010, 7:28:53 AM9/30/10
to web2py-users
Hi there,

The change of URL(...) from a string to an XML() helper bites me when
I upgrade my old web2py from trunk today.

I can change my own app's code to adapt the latest URL(...) behavior,
but am just writing to let people know there is one more scenario in
which the new URL(...) breaks code. Here is my favorite code.

response.menu = [
[ 'Home', request.url == URL(r=request, f='index'), URL(r=request,
f='index'), [] ],
[ 'About', request.url == URL(r=request, f='about'),
URL(r=request, f='about'), [] ],
....
]

The new URL(...) breaks above code because from now on,
URL(r=request) == URL(r=request)
would NEVER BE TRUE!

We have to write code like: str(URL(r=request)) ==
str(URL(r=request))


By the way, I strongly recommend Massimo to contain "link of the
discussion [1]" into hg commit log. That would make reader's life
easier.

[1] http://groups.google.com/group/web2py/browse_frm/thread/a52007de9a7c5065/8327405064ccf9c3?lnk=gst&q=URL#8327405064ccf9c3

Regards,
Iceberg

On Aug 20, 9:38 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> There is a problem (in 1.83.2 and earlier version)
>
> URL(....)
>
> returns a string, not a helper. If you want to include the string
> without escaping twice you have to do
>
> {{=XML(URL(...))}}
>
> In trunk, I modified the definition ofURLso that it returns the
> XML(..) helper wrapping the string. This will prevent
>
> {{=URL(...)}}
>
> from double escaping but will prevent you from doing
>
> 'http://127.0.0.:8000'+URL(..)
>
> you would have to do
>
> 'http://127.0.0.:8000%s'%URL(..)
>
> we cannot have it both ways.
>
> URLis either a helper or a string... The more I think about it the
> more I am convincedURLshould be a helper not a string otherwise all
> the examples in which we use {{=URL(...)}} are buggy. Therefore this
> change should be considered a bug fix and not a breaking of backward
> compatibility.
>
> What do other people think? Should we change this as in trunk or leave
> it alone?
>
> Massimo
>
> On Aug 19, 1:39 pm, Phyo Arkar <phyo.arkarl...@gmail.com> wrote:
>
>
>
> > Trunk version Rev 853
>
> > in view:
> > $("#list").jqGrid({
>
> >url:"{{=URL(r=request,f='listMIME.json',vars={'extracted_path':extracted_pa th,'source_path':source_path})}}",

mdipierro

unread,
Sep 30, 2010, 9:24:13 AM9/30/10
to web2py-users
just fixed in trunk.

On Sep 30, 6:28 am, Iceberg <iceb...@21cn.com> wrote:
> Hi there,
>
> The change of URL(...) from a string to an XML() helper bites me when
> I upgrade my old web2py from trunk today.
>
> I can change my own app's code to adapt the latest URL(...) behavior,
> but am just writing to let people know there is one more scenario in
> which the new URL(...) breaks code. Here is my favorite code.
>
> response.menu = [
>     [ 'Home', request.url == URL(r=request, f='index'), URL(r=request,
> f='index'), [] ],
>     [ 'About', request.url == URL(r=request, f='about'),
> URL(r=request, f='about'), [] ],
>     ....
>     ]
>
> The new URL(...) breaks above code because from now on,
>     URL(r=request) == URL(r=request)
> would NEVER BE TRUE!
>
> We have to write code like:  str(URL(r=request)) ==
> str(URL(r=request))
>
> By the way, I strongly recommend Massimo to contain "link of the
> discussion [1]" into hg commit log.  That would make reader's life
> easier.
>
> [1]http://groups.google.com/group/web2py/browse_frm/thread/a52007de9a7c5...
Reply all
Reply to author
Forward
0 new messages