Menu

#229 Regression in r7610 makes rst2html crash on certain links

closed-fixed
nobody
None
5
2013-03-07
2013-03-06
No

This was originally observed when buiding Python 3.3 docs (more precisely, library/unittest.mock-examples.txt) with Sphinx, but here is a minimal test case:

$ svn info | grep ^Revision
Revision: 7623
$ cat simple.rst
`__iter__ <http://example.com/#__iter__>`_.
$ ./tools/rst2html.py simple.rst --traceback
Traceback (most recent call last):
File "./tools/rst2html.py", line 23, in <module>
publish_cmdline(writer_name='html', description=description)
File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 352, in publish_cmdline
config_section=config_section, enable_exit_status=enable_exit_status)
File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 218, in publish
self.apply_transforms()
File "/usr/lib/python2.7/dist-packages/docutils/core.py", line 199, in apply_transforms
self.document.transformer.apply_transforms()
File "/usr/lib/python2.7/dist-packages/docutils/transforms/__init__.py", line 171, in apply_transforms
transform.apply(**kwargs)
File "/usr/lib/python2.7/dist-packages/docutils/transforms/references.py", line 211, in apply
self.resolve_indirect_target(target)
File "/usr/lib/python2.7/dist-packages/docutils/transforms/references.py", line 227, in resolve_indirect_target
self.nonexistent_indirect_target(target)
File "/usr/lib/python2.7/dist-packages/docutils/transforms/references.py", line 264, in nonexistent_indirect_target
self.indirect_target_error(target, 'which does not exist')
File "/usr/lib/python2.7/dist-packages/docutils/transforms/references.py", line 278, in indirect_target_error
naming += '(id="%s")' % target['ids'][0]
IndexError: list index out of range

Discussion

  • Günter Milde

    Günter Milde - 2013-03-06

    This is not a regression, but a problem with the specific kind of reference/reference name.

    The anonymous link `__iter__ <http://example.com/#__iter__>`__ works.

    The "traditional" link::

    `__iter__`_

    .. _`__iter__`: http://example.com/#__iter__

    fails as well. I suppose there is no support for refnames with leading underscore.

     
  • David Goodger

    David Goodger - 2013-03-06

    @milde: actually, I agree with the OP. This is definitely a bug, and it is a regression. It worked fine (no error, correct output, both traditional and inline URI) in r7597. A change since then must have introduced this bug (therefore, a regression).

     
  • Dmitry Shachnev

    Dmitry Shachnev - 2013-03-07

    Also, how about always treating references that start with URI scheme (i.e. [a-z]*://) as URIs? This will allow us to keep backwards compatibility, and people are unlikely to use such strings as aliases.

     
  • Günter Milde

    Günter Milde - 2013-03-07

    I agree that this is a bug, A more clear test case is::

    An `embedded alias <alias_>`_ with unknown reference.

    However, I would not call it a regression.
    It worked fine before the introduction of embedded alias references because then the embedded
    link was a URI while now (without escaping the trailing underline) it is an alias. The correct form ::

    `__iter__ <http://example.com/#__iter_\_>`_.

    works fine.

    I added a fix/workaround in transforms/references.py and a test case.
    @David: Could you please look if the fix is OK?

    @Dmitry: the suggestion to let a URI scheme override the trailing backslash should be discussed separately
    (especially as it does not solve the problem of an embedded alias with missing target).

     
  • Günter Milde

    Günter Milde - 2013-03-07
    • status: open --> closed-fixed
     
  • Dmitry Shachnev

    Dmitry Shachnev - 2013-03-08

    Thanks, it doesn't fail now (but creates a System Message instead).

    > @Dmitry: the suggestion to let a URI scheme override the trailing backslash
    > should be discussed separately
    > (especially as it does not solve the problem of an embedded alias with
    > missing target).

    It doesn't solve that, but it makes sure that we don't break existing projects (like Python's documentation). For example, at the moment I don't see any way to make my example work with both "old" and "new" docutils.

     

Log in to post a comment.