#11907 closed defect (fixed)
API docs don't display
Reported by: | Ryan J Ollos | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Component: | TracDeveloperPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 1.0 |
Description
When on the Plugin Registry page (/developer/plugins
) and trying to view the documentation for an interface, the documentation does not display and the following error is seen in the logs:
09:02:10 PM Trac[main] ERROR: Internal Server Error: Traceback (most recent call last): File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/web/main.py", line 543, in _dispatch_request dispatcher.dispatch(req) File "/home/user/Workspace/tracdev/teo-rjollos.git/trac/web/main.py", line 223, in dispatch resp = chosen_handler.process_request(req) File "/home/user/Workspace/trachacks.git/tracdeveloperplugin/trunk/tracdeveloper/apidoc.py", line 44, in process_request 'doc': formatter(req, inspect.getdoc(obj)), File "/home/user/Workspace/trachacks.git/tracdeveloperplugin/trunk/tracdeveloper/apidoc.py", line 65, in _format_default return linebreaks(text) File "/home/user/Workspace/trachacks.git/tracdeveloperplugin/trunk/tracdeveloper/util.py", line 14, in linebreaks return HTML(''.join(paras)) File "/home/user/Workspace/tracdev/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/input.py", line 442, in HTML return Stream(list(HTMLParser(BytesIO(text), encoding=encoding))) File "/home/user/Workspace/tracdev/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/core.py", line 273, in _ensure event = stream.next() File "/home/user/Workspace/tracdev/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/input.py", line 449, in _coalesce for kind, data, pos in chain(stream, [(None, None, None)]): File "/home/user/Workspace/tracdev/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-linux-x86_64.egg/genshi/input.py", line 337, in _generate raise UnicodeError("source returned bytes, but no encoding specified") UnicodeError: source returned bytes, but no encoding specified
Issue is seen in 1.0.2dev and 1.1.2dev. I haven't tested with other versions.
Attachments (1)
Change History (11)
comment:1 Changed 10 years ago by
Summary: | API docs don't display in → API docs don't display |
---|
comment:2 Changed 10 years ago by
comment:3 follow-up: 4 Changed 10 years ago by
The issue occurs with Genshi 0.7. The following patch fixes the issue, but I am unsure as to whether it is the best way:
-
tracdeveloperplugin/trunk/tracdeveloper/apidoc.py
diff --git a/tracdeveloperplugin/trunk/tracdeveloper/apidoc.py b/tracdeveloperpl index 34873b3..a7f5f64 100644
a b class APIDocumentation(Component): 46 46 } 47 47 output = Chrome(self.env).render_template(req, 'developer/apidoc.html', 48 48 data, fragment=True) 49 req.send(output.render('xhtml') , 'text/html')49 req.send(output.render('xhtml').encode('utf-8'), 'text/html') 50 50 51 51 # Internal methods 52 52 def _get_formatter(self, module): -
tracdeveloperplugin/trunk/tracdeveloper/util.py
diff --git a/tracdeveloperplugin/trunk/tracdeveloper/util.py b/tracdeveloperplug index c9b86c0..ce16f02 100644
a b def linebreaks(value): 11 11 value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines 12 12 paras = re.split('\n{2,}', value) 13 13 paras = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] 14 return HTML(''.join(paras) )14 return HTML(''.join(paras), encoding='utf-8')
comment:4 Changed 10 years ago by
Replying to rjollos:
The issue occurs with Genshi 0.7. The following patch fixes the issue, but I am unsure as to whether it is the best way:
I think it would be simple to return template and data from process_request
method rather than call directly render_template
.
-
tracdeveloper/apidoc.py
44 44 'doc': formatter(req, inspect.getdoc(obj)), 45 45 'methods': self._get_methods(req, formatter, obj) 46 46 } 47 output = Chrome(self.env).render_template(req, 'developer/apidoc.html', 48 data, fragment=True) 49 req.send(output.render('xhtml'), 'text/html') 47 return 'developer/apidoc.html', data, 'text/html' 50 48 51 49 # Internal methods 52 50 def _get_formatter(self, module):
comment:5 Changed 10 years ago by
Also, linebreaks
method has an XSS issue. For example, documentation of trac.mimeview.api:IHTMLPreviewRenderer
has <object>
and <img>
. /developer/doc/trac.mimeview.api:IHTMLPreviewRenderer
page renders thoes text without escape.
The following patch works well on Genshi 0.6 and 0.7.
-
tracdeveloper/util.py
2 2 3 3 import re 4 4 5 from genshi import HTML5 from genshi.builder import tag 6 6 7 7 def linebreaks(value): 8 8 """Converts newlines in strings into <p> and <br />s.""" … … 10 10 return '' 11 11 value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines 12 12 paras = re.split('\n{2,}', value) 13 paras = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]14 return HTML(''.join(paras))13 return tag(tag.p((line, tag.br) for line in para.splitlines()) 14 for para in paras)
comment:6 follow-up: 8 Changed 10 years ago by
Another thing: I think /developer/api
should require TRAC_DEVELOP
permission. Currently, anyone can let to import any objects using the feature.
-
tracdeveloper/apidoc.py
29 29 return True 30 30 31 31 def process_request(self, req): 32 req.perm.require('TRAC_DEVELOP') 32 33 modname, attrname = str(req.args['name']).split(':') 33 34 try: 34 35 module = __import__(modname, {}, {}, filter(None, [attrname]))
comment:7 Changed 10 years ago by
Changed 10 years ago by
Attachment: | t11907.diff added |
---|
comment:8 Changed 10 years ago by
Another thing: I think
/developer/api
should requireTRAC_DEVELOP
permission. Currently, anyone can let to import any objects using the feature.
Reconsidered about that, I think it would safe to use sys.modules
rather than __import__
. See attachment:t11907.diff.
comment:10 Changed 10 years ago by
Owner: | changed from Olemis Lang to Jun Omae |
---|
Side note: there is an unresolved reference here: tracdeveloperplugin/trunk/tracdeveloper/apidoc.py@3230:62#L51.