Edgewall Software
Modify

Opened 10 years ago

Last modified 3 years ago

#11432 new defect

The href of customized navigation items doesn't work as documented

Reported by: Ryan J Ollos Owned by:
Priority: normal Milestone: next-dev-1.7.x
Component: general Version:
Severity: normal Keywords: navigation bitesized
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

TracNavigation#Notes suggests that the following mappings should occur:

  • /projects/project1/wiki/WikiStart/projects/projects1/wiki/WikiStart
  • wiki/WikiStart/projects/project1/wiki/WikiStart (when in the project1 environment).

This is not the case however. An href beginning with / is treated as project-relative. There does not seem to be a way to create an interproject link in a multiproject/multienvironment setup sharing the same base url link without using the base url in the href or using .. in the href (e.g. ../project2/wiki/WikiStart).

Using an href such as wiki/WikiStart results in repeated clicks on the mainnav button mapping to /projects/project1/wiki/WikiStart/projects/project1/wiki/WikiStart/wiki/WikiStart/projects/project1/wiki/WikiStart/wiki/WikiStart/wiki/WikiStart.

Unfortunately I think the proper fix would change the behavior for existing users:

  • trac/web/chrome.py

    diff --git a/trac/web/chrome.py b/trac/web/chrome.py
    index f627ae5..7b392f3 100644
    a b class Chrome(Component):  
    724724                        label = category_section.get(name + '.label')
    725725                        href = category_section.get(name + '.href')
    726726                        if href:
    727                             if href.startswith('/'):
     727                            if not href.startswith(('http://',
     728                                                    'https://', '/')):
    728729                                href = req.href + href
    729730                            if label:
    730731                                item = tag.a(label) # create new label

Attachments (0)

Change History (8)

in reply to:  description comment:1 by Olemis Lang <olemis+trac@…>, 10 years ago

Replying to rjollos: […]

This is not the case however. An href beginning with / is treated as project-relative.

yes

There does not seem to be a way to create an interproject link in a multiproject/multienvironment setup sharing the same base url

afaik , no … unless InterTrac or a custom TracLinks expression is installed .

Using an href such as wiki/WikiStart results in repeated clicks on the mainnav button mapping to /projects/project1/wiki/WikiStart/projects/project1/wiki/WikiStart/wiki/WikiStart/projects/project1/wiki/WikiStart/wiki/WikiStart/wiki/WikiStart.

wiki/WikiStart is a relative wiki path , varies depending on (wiki) context

Unfortunately I think the proper fix would change the behavior for existing users:

yep, I'm not very sure about it …

[…]

comment:2 by Ryan J Ollos, 10 years ago

Milestone: next-stable-1.0.xnext-dev-1.1.x
Owner: set to Ryan J Ollos
Status: newassigned

Since either the documentation needs to be changed or the patch needs to be applied, I vote for applying the patch on the trunk since it make the configuration more flexible, and documenting the behavior for Trac < 1.2. That will avoid breaking configurations on 1.0-stable and earlier.

For example, after the patch is applied a user that has an href = /wiki/WikiStart with a base URL for the project http://example.com/proj1 will need to change to href = wiki/WikiStart otherwise the link will direct to http://example.com/wiki/WikiStart. However, after the patch a link can be created to another project using href = /proj2/wiki/WikiStart, which will map to http://example.com/proj2/wiki/WikiStart. See th:#11443 for a related issue.

I'll wait for feedback from the other Trac devs before proceeding.

comment:3 by ethan.jucovy@…, 10 years ago

A backwards-compatible alternative for interproject links might be href = //proj2/wiki/WikiStart. Personally I would find that + the current behavior less surprising than resolving relative links to the project base.

(Though perhaps // should be interpreted as a protocol-relative absolute URL, as it would be if seen directly in a browser. It currently just becomes http://example.com/proj1//proj2/wiki/WikiStart which is almost certainly never useful.)

Granted, relative links don't seem like a very desirable feature for the mainnav. I can imagine (maybe still unlikely) uses for relative links in the metanav though, in plugins that also implement IRequestHandler — e.g. contextual help, or "create a ticket linked to the page I'm on", or "show me API functions available for this resource".

comment:4 by Ryan J Ollos, 9 years ago

Owner: Ryan J Ollos removed
Status: assignednew

comment:5 by Ryan J Ollos, 9 years ago

Keywords: bitesized added

comment:6 by Ryan J Ollos, 8 years ago

Milestone: next-dev-1.1.xnext-dev-1.3.x

comment:7 by Ryan J Ollos, 5 years ago

Milestone: next-dev-1.3.xnext-dev-1.5.x

Milestone renamed

comment:8 by Ryan J Ollos, 3 years ago

Milestone: next-dev-1.5.xnext-dev-1.7.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.