Skip to content

Commit

Permalink
Fix #6561: glossary: Wrong hyperlinks are generated for non alphanume…
Browse files Browse the repository at this point in the history
…ric terms
  • Loading branch information
tk0miya committed Jul 8, 2019
1 parent ef2f105 commit b563906
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Bugs fixed
* #5592: std domain: :rst:dir:`option` directive registers an index entry for
each comma separated option
* #6549: sphinx-build: Escaped characters in error messages
* #6561: glossary: Wrong hyperlinks are generated for non alphanumeric terms

Testing
--------
Expand Down
6 changes: 3 additions & 3 deletions sphinx/domains/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def make_glossary_term(env: "BuildEnvironment", textnodes: Iterable[Node], index
new_id = nodes.make_id('term-' + termtext)
if new_id == 'term':
# the term is not good for node_id. Generate it by sequence number instead.
new_id = 'term-' + str(len(gloss_entries))
if new_id in gloss_entries:
new_id = 'term-' + str(len(gloss_entries))
new_id = 'term-%d' % env.new_serialno('glossary')
while new_id in gloss_entries:
new_id = 'term-%d' % env.new_serialno('glossary')
gloss_entries.add(new_id)

std = cast(StandardDomain, env.get_domain('std'))
Expand Down
11 changes: 11 additions & 0 deletions tests/test_domain_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ def test_glossary_sorted(app):
[nodes.definition, nodes.paragraph, "description"])


def test_glossary_alphanumeric(app):
text = (".. glossary::\n"
"\n"
" 1\n"
" /\n")
restructuredtext.parse(app, text)
objects = list(app.env.get_domain("std").get_objects())
assert ("1", "1", "term", "index", "term-1", -1) in objects
assert ("/", "/", "term", "index", "term-0", -1) in objects


def test_cmdoption(app):
text = (".. program:: ls\n"
"\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_environment_indexentries.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ def test_create_index_by_key(app):
assert len(index) == 3
assert index[0] == ('D', [('docutils', [[('main', '#term-docutils')], [], None])])
assert index[1] == ('P', [('Python', [[('main', '#term-python')], [], None])])
assert index[2] == ('ス', [('スフィンクス', [[('main', '#term-2')], [], 'ス'])])
assert index[2] == ('ス', [('スフィンクス', [[('main', '#term-0')], [], 'ス'])])

0 comments on commit b563906

Please sign in to comment.