Modify

Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#7680 closed defect (duplicate)

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

Reported by: shesek Owned by: cbalan
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 shesek 4 years ago.
menusplugin-path-2.patch (839 bytes) - added by shesek 4 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 4 years ago by shesek

comment:1 Changed 4 years ago by shesek

  • Keywords patch added
  • Summary changed from Invalid links when trac is on accessed from top-most path to [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 follow-up: Changed 4 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 4 years ago by shesek

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

comment:3 Changed 2 years ago by rjollos

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

comment:4 Changed 2 years ago by rjollos

(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 2 years ago by rjollos

(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 ; follow-up: Changed 2 years ago by rjollos

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 2 years ago by rjollos

(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 2 years ago by rjollos

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

comment:9 Changed 2 years ago by rjollos

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

comment:10 in reply to: ↑ 6 Changed 2 years ago by rjollos

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 2 years ago by rjollos

(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 2 years ago by rjollos

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).

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from cbalan. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.