Export to GitHub

robotframework - issue #1678

Libdoc: Links to keywords not percent encoded


Posted on Mar 11, 2014 by Happy Wombat

The internal links in the shortcut section that libdoc generates have spaces in the href. URLs should not contain whitespace (should be percent encoded). When referring someone to a keyword one often right-clicks on the shortcut and copies the link. When pasting in forum posts, emails, etc. the links end up invalid or only working in certain browsers. There are several links lately that have the spaces converted to pluses and the links are not working in Chrome. The name attribute can still have a space in it: <td class="kw"><a name="Set Variable"></a>Set Variable</td> But the link to it should not have a space. It should be: <a href="#Set%20Variable" title="Returns the given values which can then be assigned to a variables.">Set Variable</a> Instead it is: <a href="#Set Variable" title="Returns the given values which can then be assigned to a variables.">Set Variable</a>

Comment #1

Posted on Mar 11, 2014 by Happy Wombat

Problem is caused by building a URL with string formatting alone without using urllib.quote robot/libdocpkg/htmlwriter.py line 116 return '%s' % (self._targets[name], name)

Comment #2

Posted on Mar 11, 2014 by Happy Wombat

Please ignore comment #1 - wrong place in the code. I was able to get percent encoded URLs by changing line 92 in robot/htmldata/libdoc/libdoc.html: From: ${$value.name} To: ${$value.name}

Not sure if this is the best way to fix this.

Comment #3

Posted on Mar 12, 2014 by Happy Rhino

I've noticed this problem too. Let's see does using encodeURIComponent like you proposed fix the issue.

Comment #4

Posted on Apr 22, 2014 by Happy Rhino

encodeURIComponent like proposed by @kormbrek fixes the problem in the shortcut section but not with cross-references between keywords and library introduction. Luckily fixing that in Python code when generating the documentation isn't too hard.

Comment #5

Posted on Apr 22, 2014 by Happy Rhino

This issue was updated by revision 08b120e0dc78.

This commit contains follawing changes: - Links to keywords in Shortcuts section are percent encoded using encodeURIComponent in HTML template. - Cross-reference links are percent encoded in Python by emulating encodeURIComponent using urllib.quote. - Cross-reference matching when target name contains HTML entities (&<>) is fixed.

Comment #6

Posted on Apr 22, 2014 by Happy Rhino

This issue was updated by revision c987c472da41.

Better test data for manually testing generated docs. The file to use is visible here: https://robotframework.googlecode.com/hg/src/robot/htmldata/libdoc/libdoc.html

Status: Done

Labels:
Type-Defect Priority-Medium Target-2.8.5