Modify

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#7680 closed defect (duplicate)

[PATCH] Invalid links when trac is on accessed from top-most path

Reported by: HumanInternals Owned by: Catalin BALAN
Priority: normal Component: MenusPlugin
Severity: normal Keywords: patch
Cc: Trac Release: 0.12

Description

The links in that ticket were considered as being spam, so I added \notspam\ to prevent that from happening. Ignore it.

My Trac installation is accessed via http://trac.kelso/. When I add a menu, like that:

query = enabled
query.href = /query
query.label = Custom Query
query.order = 1
query.parent = tickets

It's being rendered as <a \notspam\ href="//query">Custom Query</a>. The // at the beginning of the href causes Chrome and Firefox (and possibly others) to think its a link to "http://query/".

When I remove the / prefix from the href in the configuration, the link becomes <a \notspam\ href="query">Custom Query</a>, which doesn't work when I'm on a URL like 'http://trac.kelso/ticket/123', as the link is pointing to 'http:trac.kelso/ticket/query'.

It works fine when Trac is installed under a sub directory, such as http://trac.kelso/humaninternals/, as the link is rendered as <a \notspam\ href="/humaninternals/query">Custom Query</a>. The issue is when its rendered with two slashes at the beginning.

Attachments (2)

menusplugin-path.patch (790 bytes) - added by HumanInternals 14 years ago.
menusplugin-path-2.patch (839 bytes) - added by HumanInternals 14 years ago.
a working patch, as described in comment:2 (was written by me, but I forgot to login)

Download all attachments as: .zip

Change History (14)

Changed 14 years ago by HumanInternals

Attachment: menusplugin-path.patch added

comment:1 Changed 14 years ago by HumanInternals

Keywords: patch added
Summary: Invalid links when trac is on accessed from top-most path[PATCH] Invalid links when trac is on accessed from top-most path

Attaching a fix that worked for me - using req.href() with an argument, instead of concating it with the href.

comment:2 Changed 14 years ago by anonymous

The last patch doesn't work properly, as the href is encoded (so characters like '?' won't work). It's not possible to pass as an argument to req.href(), so I'm uploading a new patch right-strips the base href from '/' characters (href=value.startswith('/') and req.href().rstrip('/')+value or value)

Changed 14 years ago by HumanInternals

Attachment: menusplugin-path-2.patch added

a working patch, as described in comment:2 (was written by me, but I forgot to login)

comment:3 Changed 13 years ago by Ryan J Ollos

Resolution: duplicate
Status: newclosed

Duplicate of #7399.

comment:4 Changed 13 years ago by Ryan J Ollos

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

comment:5 Changed 13 years ago by Ryan J Ollos

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

comment:6 in reply to:  2 ; Changed 13 years ago by Ryan J Ollos

Replying to anonymous:

The last patch doesn't work properly, as the href is encoded (so characters like '?' won't work). It's not possible to pass as an argument to req.href(),

I tried some examples using the patch described in comment:10:ticket:7399, and it seems to work fine to pass the value to req.href.

Here is one of the examples I tried:

/timeline?from=01%2F17%2F2012&daysback=30&changeset=on&milestone=on&wiki=on&update=Update

comment:7 Changed 13 years ago by Ryan J Ollos

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

comment:8 Changed 13 years ago by Ryan J Ollos

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

comment:9 Changed 13 years ago by Ryan J Ollos

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

comment:10 in reply to:  6 Changed 13 years ago by Ryan J Ollos

Replying to rjollos:

I tried some examples using the patch described in comment:10:ticket:7399, and it seems to work fine to pass the value to req.href.

Here is one of the examples I tried:

/timeline?from=01%2F17%2F2012&daysback=30&changeset=on&milestone=on&wiki=on&update=Update

My statement here is incorrect. This does not work. I'll be trying to resolve it over in #7399.

comment:11 Changed 13 years ago by Ryan J Ollos

(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'.

comment:12 Changed 13 years ago by Ryan J Ollos

I'm working a similar issue in #9788 for the BookmarkPlugin, and considering that href = req.path_info + value might be equivalent to and cleaner than the code fragment (req.href().rstrip('/') + value).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Catalin BALAN.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.