Skip to content

Commit

Permalink
Merge pull request #309 from xxyzz/ns
Browse files Browse the repository at this point in the history
Return empty string for `{{ns:0}}` and `{{ns:}}`
  • Loading branch information
xxyzz authored Sep 19, 2024
2 parents 4763687 + 6b22431 commit 66545a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wikitextprocessor/parserfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ def ns_fn(
https://www.mediawiki.org/wiki/Help:Magic_words#Namespaces_2
"""
arg = expander(args[0]).strip() if args else ""
if arg in ["0", ""]:
return ""
lc_arg = arg.lower()
for key, ns in wtp.NAMESPACE_DATA.items():
if arg.isdigit() and ns["id"] == int(arg):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_parserfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,9 @@ def test_rel2abs(self):
for wikitext, result in test_cases:
with self.subTest(wikitext=wikitext, result=result):
self.assertEqual(self.wtp.expand(wikitext), result)

def test_ns_empty_str(self):
# https://ru.wiktionary.org/wiki/Шаблон:--lang--
self.wtp.start_page("test")
self.assertEqual(self.wtp.expand("{{ns:0}}"), "")
self.assertEqual(self.wtp.expand("{{ns:}}"), "")

0 comments on commit 66545a6

Please sign in to comment.