Edgewall Software
Modify

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11277 closed defect (fixed)

Unexpected results using add_script with network-path references

Reported by: Olemis Lang <olemis+trac@…> Owned by: Olemis Lang <olemis+trac@…>
Priority: normal Milestone: 1.0.2
Component: general Version: 1.1.1dev
Severity: minor Keywords: patch, http link uri url
Cc: Branch:
Release Notes:

Network-path references (URLs starting with //) are supported for the [trac] options jquery_location, jquery_ui_location and jquery_ui_theme_location.

API Changes:

Network-path references (URLs starting with //) are supported for scripts and stylesheets added using add_script and add_stylesheet.

Internal Changes:

Description

During the last years network-path references are used more often due to the popularity of CDN solutions, the deployment of http/https/spdy/… and some issues in browsers (particularly MSIE) when switching to a different scheme to retrieve linked resources.

When trying to use add_script (or similar) function with network-path references this is what I get

>>> from wsgiref.util import setup_testing_defaults
>>> environ = {}
>>> setup_testing_defaults(environ)
>>> from trac.web.api import Request
>>> req = Request(environ, lambda *args, **kwargs: None)
>>> req.locale = None
>>> from trac.env import open_environment as oe
>>> env = oe('/srv/trac/cleanmp')
>>> from trac.web.chrome import Chrome
>>> from trac.web import chrome
>>> req.callbacks['chrome'] = chrome.Chrome(env).prepare_request
>>> chrome.add_script(req, '//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js')
>>> from pprint import pprint
>>> pprint(req.chrome['scripts'])
[{'charset': 'utf-8',
  'href': '/chrome/common/js/jquery.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/babel.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/trac.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/search.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'}]

As can be seen it will not be expanded correctly.

N.B. Version in /trunk is 1.1.2 but I did not see such option in versions selector .

Attachments (0)

Change History (7)

comment:1 by Olemis Lang <olemis+trac@…>, 11 years ago

Keywords: uri url added
Summary: Unexpected results using Href with network-path referencesUnexpected results using add_script with network-path references

comment:2 by Olemis Lang <olemis+trac@…>, 11 years ago

After applying this patch expected results are obtained

>>> from wsgiref.util import setup_testing_defaults
>>> environ = {}
>>> setup_testing_defaults(environ)
>>> from trac.web.api import Request
>>> req = Request(environ, lambda *args, **kwargs: None)
>>> req.locale = None
>>> from trac.env import open_environment as oe
>>> env = oe('/srv/trac/cleanmp')
>>> from trac.web.chrome import Chrome
>>> from trac.web import chrome
>>> req.callbacks['chrome'] = chrome.Chrome(env).prepare_request
>>> chrome.add_script(req, '//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js')
>>> from pprint import pprint
>>> pprint(req.chrome['scripts'])
[{'charset': 'utf-8',
  'href': '/chrome/common/js/jquery.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/babel.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/trac.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '/chrome/common/js/search.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'},
 {'charset': 'utf-8',
  'href': '//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js',
  'prefix': None,
  'suffix': None,
  'type': 'text/javascript'}]

comment:3 by Ryan J Ollos, 11 years ago

Milestone: 1.0.2
Owner: set to Ryan J Ollos
Status: newassigned

I've tested the changes and everything looks good: rjollos.git:t11277.

The major question I have for the other Trac devs is about the naming of the function _chrome_resource_path - maybe someone will come up with a better function name - and whether the function should be public or private. I've made it private since it didn't seem very useful outside of the chrome module.

comment:4 by Christian Boos, 11 years ago

LGTM, including the name of the helper function.

comment:5 by Ryan J Ollos, 11 years ago

API Changes: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [11975-11976]. Merged to trunk in [11977].

comment:6 by Ryan J Ollos, 11 years ago

Owner: changed from Ryan J Ollos to Olemis Lang <olemis+trac@…>

Thanks Olemis!

comment:7 by Ryan J Ollos, 11 years ago

Refactored _chrome_resource_path in [12622:12623].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Olemis Lang <olemis+trac@…>.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Olemis Lang <olemis+trac@…> to the specified user.

Add Comment


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