Skip to content

Commit

Permalink
Merge pull request tatuylonen#148 from xxyzz/unescape
Browse files Browse the repository at this point in the history
Don't process Template args with `html.unescape()`
  • Loading branch information
xxyzz authored Nov 28, 2023
2 parents de5b4c7 + a775218 commit 396f23a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/wikitextprocessor/luaexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ def make_frame(
frame_args = {}
for k, arg in args.items():
arg = re.sub(r"(?si)<\s*noinclude\s*/\s*>", "", arg)
arg = html.unescape(arg)
frame_args[k] = arg
else:
assert isinstance(args, (list, tuple))
Expand Down Expand Up @@ -528,7 +527,6 @@ def make_frame(
# does not always like them (e.g., remove_links() in
# Module:links).
arg = re.sub(r"(?si)<\s*noinclude\s*/\s*>", "", arg)
arg = html.unescape(arg)
frame_args[k] = arg
frame_args_lt: "_LuaTable" = lua.table_from(frame_args) # type: ignore[union-attr]

Expand Down
37 changes: 31 additions & 6 deletions tests/test_node_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# Copyright (c) 2020-2021 Tatu Ylonen. See file LICENSE and https://ylonen.org

import unittest

from unittest.mock import patch

from wikitextprocessor import Wtp, Page
from wikitextprocessor import Page, Wtp


class NodeExpTests(unittest.TestCase):
Expand Down Expand Up @@ -206,7 +205,6 @@ def test_blank_template(self, mock_get_page) -> None:
"""
self.totext("{{blank template}}", "")


def test_language_converter_placeholder(self) -> None:
# "-{}-" template argument shouldn't be cleaned before invoke Lua module
# GitHub issue #59
Expand All @@ -215,7 +213,7 @@ def test_language_converter_placeholder(self) -> None:
self.ctx.add_page(
"Template:Ja-romanization of",
10,
"{{#invoke:form of/templates|form_of_t|-{}-|withcap=1|lang=ja}}"
"{{#invoke:form of/templates|form_of_t|-{}-|withcap=1|lang=ja}}",
)
# https://zh.wiktionary.org/wiki/Module:Form_of/templates
self.ctx.add_page(
Expand All @@ -232,11 +230,38 @@ def test_language_converter_placeholder(self) -> None:
end
return export
""",
model="Scribunto"
model="Scribunto",
)
self.ctx.db_conn.commit()
self.ctx.start_page("test_page")
self.assertEqual(
self.ctx.expand("{{ja-romanization of|まんが}}"),
"[[まんが#日語|まんが]]</i></span> </span>"
"[[まんが#日語|まんが]]</i></span> </span>",
)

def test_lua_module_args_not_unescaped(self):
# https://en.wiktionary.org/wiki/Gendergap
self.ctx.add_page(
"Template:quote-journal",
10,
"{{#invoke:quote|quote_t|type=journal}}",
)
self.ctx.add_page(
"Module:quote",
828,
"""
local export = {}
function export.quote_t(frame)
return frame:getParent().args.title
end
return export
""",
model="Scribunto",
)
self.ctx.start_page("Gendergap")
self.assertEqual(
self.ctx.expand(
"{{quote-journal|de|title=re&colon;publica 2014, der 1.}}"
),
"re&colon;publica 2014, der 1.",
)

0 comments on commit 396f23a

Please sign in to comment.