Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx crashes when the translation catalog contains invalid footnote references #8745

Closed
shimizukawa opened this issue Jan 23, 2021 · 1 comment

Comments

@shimizukawa
Copy link
Member

Describe the bug
Normally, building a document with invalid footnote references will not cause a crash.
However, if the translation catalog contains invalid footnote references, it will crash during the write phase.

To Reproduce
Normal case will emit warnings, but will not crash.
index.rst

Hello
========

* a invalid auto-numbered [#]_ ref.
* a invalid named [1]_ ref.

this emits...

...(snip)...
reading sources... [100%] index
test/index.rst:4: WARNING: Too many autonumbered footnote references: only 0 corresponding footnotes available.
test/index.rst:5: WARNING: Unknown target name: "1".
...(snip)...
build succeeded, 2 warnings.

However, invalid footnote references in translation catalog files, sphinx will crash on writing phase.

index2.rst

Hello
========

* this is literal ``[#]_`` ref.
* this is literal ``[1]_`` ref.

index2.po

msgid "this is literal ``[#]_`` ref."
msgstr "this is literal ''[#]_'' ref."

msgid "this is literal ``[#]_`` ref."
msgstr "this is literal ''[1]_'' ref."

In this example, the backticks were mistakenly changed to single quotes in the translation catalog file, resulting in a footnote reference that is not in the source.
If you build with this translation catalog, you will get the following error:

test> sphinx-build -M html . _build -Dlanguage=ja
Running Sphinx v4.0.0+/37fc43a4d
loading translations [ja]... done
building [mo]: targets for 1 po files that are out of date
writing output... [100%] locale/ja/LC_MESSAGES/index2.mo
building [html]: targets for 2 source files that are out of date
updating environment: [new config] 2 added, 0 changed, 0 removed
reading sources... [100%] index2
test/index.rst:4: WARNING: Too many autonumbered footnote references: only 0 corresponding footnotes available.
test/index.rst:5: WARNING: Unknown target name: "1".
test/index2.rst:4: WARNING: inconsistent footnote references in translated message. original: [], translated: ['[#]_']
test/index2.rst:5: WARNING: inconsistent footnote references in translated message. original: [], translated: ['[1]_']
test/index2.rst:5: WARNING: Unknown target name: "1".
looking for now-outdated files... none found
pickling environment... done
checking consistency... C:\Project\sphinx-dev\sphinx-doc-translations\test\index2.rst: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [100%] index2
Exception occurred:
  File ".venv\lib\site-packages\docutils\nodes.py", line 625, in __getitem__
    return self.attributes[key]
KeyError: 'refid'

Expected behavior
No crash

Your project
test.zip

Environment info

  • OS: Windows, Linux
  • Python version: 3.9.0
  • Sphinx version: 4.0.0
  • Sphinx extensions: nothing
  • Extra tools: nothing

Additional context
Actual case

@shimizukawa shimizukawa self-assigned this Jan 23, 2021
@tk0miya tk0miya added this to the 3.5.0 milestone Jan 24, 2021
tk0miya added a commit that referenced this issue Jan 27, 2021
…note_refs

Fix #8745: i18n: KeyError if a new auto footnote_ref in translations
@shimizukawa
Copy link
Member Author

Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants