Opened 4 years ago

Closed 4 years ago

Allow non-project relative (absolute) links again.

Reported by: Owned by: ryank-inovonics Ryan J Ollos normal NavAddPlugin normal 1.0

Description

With the fix for #940, this plugin only allowed links relative to the Trac environment to be used. While this is handy for multiple instance setups, it does prevent the use of absolute links to resources outside the Trac environment.

The attached patch checks the provided href to see if it starts with https:, http:, or /. If it does then the URL is used in the nav bar item directly. Otherwise it is left as a link relative to the Trac environment.

Changed 4 years ago by ryank-inovonics

Restore support for absolute URLs.

comment:1 Changed 4 years ago by Ryan J Ollos

Owner: changed from Michael Renzmann to Ryan J Ollos new → assigned

comment:2 Changed 4 years ago by Ryan J Ollos

For the case that the href starts with /, do you treat it as relative to the network location (e.g. http://www.myserver.com)?

For example, if the base of a project is /proj1, then wiki/WikiStart maps to /proj1/wiki/WikiStart, but an href starting with / would need to start with the project name (.e.g /proj2)?

comment:3 Changed 4 years ago by ryank-inovonics

That is correct, some examples for a Trac installed at https://www.myserver.com/trac/:

hrefLink in page source.Link as displayed/used by web browser.
/reviewboard//reviewboard/https://www.myserver.com/reviewboard/
report/43/trac/report/43https://trac.inovonics.com/trac/report/43
https://www.other.com/https://www.other.com/https://www.other.com/

I chose this logic as it let you specify links relative to the Trac instance, the server hosting Trac instance(s), or an absolute location with a single config value.

comment:4 Changed 4 years ago by Ryan J Ollos

The rules you suggest make sense. The changes would be inconsistent with the rules used for the MenusPlugin, but that plugin should probably be changed since it doesn't allow for links on the same base URL without specifying the full URL.

comment:5 Changed 4 years ago by Ryan J Ollos

Status: assigned → accepted

comment:6 Changed 4 years ago by Ryan J Ollos

Your suggestions agree with the documentation for [mainnav] and [metanav] at TracNavigation. However, I found that similar problems exist in Trac: trac:#11432.

comment:7 Changed 4 years ago by Ryan J Ollos

Resolution: → fixed accepted → closed

In 13554:

0.3: An href starting with a / is relative to the base URL, and absolute URLs are treated as such. Fixes #11443.

Removed some unused code. Thanks to ryank-inovonics for the patch.

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:8 Changed 4 years ago by Ryan J Ollos

If you have a chance to test out the latest code and report back whether it is working for you, that would be appreciated.

comment:9 Changed 4 years ago by Ryan J Ollos

Documentation updated.

comment:10 Changed 4 years ago by ryank-inovonics

Works great! Thanks.

Modify Ticket

Change Properties