Ticket #7399 (closed defect: fixed)

Opened 3 years ago

Expand one more "/" while parsing "href"

Reported by: Assigned to: anonymous rjollos normal MenusPlugin normal chuang@tecomtech.com 0.12

Description

I found when you configure as below in trac.ini

browser_timeline = enabled
browser_timeline.label = Recent Changes
browser_timeline.href = /timeline?changeset=on
browser_timeline.parent = browsergrp
browser_timeline.order = 30

it will translate to html segment like "a href="//timeline?changeset=on">Recent Changes</a>", here one more "/" is added so it doesn't work.


Change History

07/21/10 10:36:43 changed by anonymous

menu[name]['label']=menu[name].setdefault('label', html.a())(href=value.startswith('/') and req.href()+value or value)


--->

menu[name]['label']=menu[name].setdefault('label', html.a())(href=value.startswith('/') and value or req.href()+value)


12/14/11 07:10:37 changed by rjollos

• owner changed from cbalan to rjollos.
• status changed from new to assigned.

#7680, #8877 and #8953 closed as duplicates.

12/14/11 07:28:29 changed by rjollos

• status changed from assigned to closed.
• resolution set to fixed.

(In [11038]) Fixes #7399, Refs #7680, #8877, #8953: (0.1.1) Links were invalid when Trac was accessed from the top-most path.

12/14/11 07:42:23 changed by rjollos

Well, I think #7680 had a better solution.

12/14/11 07:45:43 changed by rjollos

(In [11039]) Fixes #7399, Refs #7680, #8877, #8953: (0.1.1) [11038] was the wrong solution. This fix should work better.

01/04/12 13:49:14 changed by dom@dotzteam.com

• status changed from closed to reopened.
• resolution deleted.

Hi guys!

The fix in r11039 is still not working. This should be the right line.

menu[name]['label']=menu[name].setdefault('label', html.a())(href=value.startswith('/') and (req.href().rstrip('/') + value) or value)


(follow-up: ↓ 8 ) 01/04/12 15:02:09 changed by osimons

Sorry for butting in, but can't that just be written as href=req.href(value)? The Href class is supposed to take care of the path joining for its arguments.

(in reply to: ↑ 7 ; follow-ups: ↓ 9 ↓ 10 ) 01/04/12 15:06:44 changed by osimons

Sorry for butting in, but can't that just be written as href=req.href(value)? The Href class is supposed to take care of the path joining for its arguments.

Actually, in some older versions of Href that may not be the case. So to be sure I guess it can be slightly modified to href=req.href(value.lstrip('/')) just to be sure that it works across all versions for 0.11 -> 0.13dev.

(in reply to: ↑ 8 ) 01/04/12 16:27:12 changed by rjollos

Actually, in some older versions of Href that may not be the case. So to be sure I guess it can be slightly modified to href=req.href(value.lstrip('/')) just to be sure that it works across all versions for 0.11 -> 0.13dev.

I appreciate the feedback! I'll make that change and do some testing against the two versions this evening and commit the change.

(in reply to: ↑ 8 ) 01/18/12 07:20:16 changed by rjollos

Actually, in some older versions of Href that may not be the case. So to be sure I guess it can be slightly modified to href=req.href(value.lstrip('/')) just to be sure that it works across all versions for 0.11 -> 0.13dev.

It looks like the issue was probably fixed by 0.11: href @ 0.11. I did some testing and the change you suggested is working nicely against 0.11 and the latest trunk. I'll commit that fix shortly.

dom: could you please let me know the result of testing on your Trac instance? Thanks!

01/18/12 09:51:15 changed by rjollos

• status changed from reopened to closed.
• resolution set to fixed.

(In [11154]) Fixes #7399, Refs #7680, #8877, #8953: Allow Href to take care of path joining. Tested in 0.11 and 0.13dev-r10909.

01/18/12 09:57:17 changed by rjollos

(In [11155]) Fixes #7399, Refs #7680, #8877, #8953: Removed egg and pydev files accidentally committed in [11154].

01/18/12 09:58:12 changed by rjollos

(In [11156]) Fixes #7399, Refs #7680, #8877, #8953: Removed egg and pydev files accidentally committed in [11154].

01/18/12 10:00:52 changed by rjollos

Sorry about [11155] and [11156]. I was trying out Subversive in Eclipse and I feel like it lied to me with the commit list.

01/18/12 11:03:50 changed by rjollos

• status changed from closed to reopened.
• resolution deleted.

I seem to have overlooked two things. One is that absolute URLs can be used in the href field. As long as the URLs begin with the scheme, that can be handled without much trouble:

href = urlparse(value).scheme and value or req.href(value)


The second issue was noted comment:2:ticket:7680. If the string contains query or path arguments, they get quoted. For example, newticket_defect.href = newticket?type=defect results in /tracenv/newticket%3Ftype%3Ddefect and the error No handler matched request to /newticket?type=defect.

osimons, do you have any suggestions on how best to proceed? Maybe I should cut everything after and including the ? character and then append it back after passing the result to req.href?

(follow-up: ↓ 17 ) 01/18/12 15:53:52 changed by osimons

And the value can even have a #fragment in addition to the query string or instead of the query string.

I don't know. I just commented with a simplification of a particular suggestion in comments, but have no inclination to find out what the "right" thing would be for this plugin in this context... Sorry :-)

(in reply to: ↑ 16 ) 01/18/12 18:44:34 changed by rjollos

And the value can even have a #fragment in addition to the query string or instead of the query string. I don't know. I just commented with a simplification of a particular suggestion in comments, but have no inclination to find out what the "right" thing would be for this plugin in this context... Sorry :-)

No problem. I think I'll go back to building up the href manually. I need to work out more clearly what the possible cases are, but it seems like a brute-force way would be something like:

req.href.rstrip('/') + '/' + value.lstrip('/')


01/20/12 15:51:23 changed by rjollos

comment:6 seems like the best solution here ... or at least the best I'm going to be able to do for now.

01/20/12 16:04:16 changed by rjollos

• status changed from reopened to closed.
• resolution set to fixed.

(In [11166]) Fixes #7399, Refs #7680, #8877, #8953: Yet another attempt to fix invalid links when req.href = '/'. If the href for a menu item specifies a relative path, the trailing forward slashes are stripped from req.href() so that the two cases are handled: 1) req.href() is '/' and 2) req.href() is '/somepath'.

Add/Change #7399 (Expand one more "/" while parsing "href")

Change Properties