Edgewall Software
Modify

Opened 8 months ago

Last modified 7 months ago

#11432 assigned defect

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

Reported by: rjollos Owned by: rjollos
Priority: normal Milestone: next-dev-1.1.x
Component: general Version:
Severity: normal Keywords: navigation
Cc:
Release Notes:
API 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 (3)

comment:1 in reply to: ↑ description Changed 8 months ago by Olemis Lang <olemis+trac@…>

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 Changed 8 months ago by rjollos

  • Milestone changed from next-stable-1.0.x to next-dev-1.1.x
  • Owner set to rjollos
  • Status changed from new to assigned

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 Changed 7 months ago by ethan.jucovy@…

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned The owner will remain rjollos.
The ticket will be disowned. Next status will be 'new'.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from rjollos to the specified user.
Author


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

 
Note: See TracTickets for help on using tickets.