Skip to content

Commit 4230888

Browse files
authored
Merge pull request #359 from xxyzz/anchorEncode
Fix Lua error in reconstruction pages
2 parents 47d8b20 + 77e75b0 commit 4230888

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wikitextprocessor/lua/mw_uri.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ local mw_uri = {
228228

229229
function mw_uri.anchorEncode(s)
230230
-- XXX how exactly should this work?
231-
s = s:gsub(" ", "_"):gsub("*", "*")
231+
s = s:gsub(" ", "_"):gsub("&#x(%x+);", function(hex)
232+
return string.char(tonumber(hex, 16))
233+
end):gsub("&#(%d+);", function(num)
234+
return string.char(tonumber(num))
235+
end)
232236
return s
233237
end
234238

tests/test_lua.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,17 @@ def test_math_module_sum(self):
584584
return export""",
585585
)
586586
self.assertEqual(self.wtp.expand("{{#invoke:math|sum}}"), "1")
587+
588+
def test_mw_uri_anchorEncode(self):
589+
# GH PR #276
590+
self.wtp.start_page("Reconstruction:Proto-Turkic/us-")
591+
self.wtp.add_page(
592+
"Module:test",
593+
828,
594+
"""local export = {}
595+
function export.test(frame)
596+
return mw.uri.anchorEncode("*") .. mw.uri.anchorEncode("*")
597+
end
598+
return export""",
599+
)
600+
self.assertEqual(self.wtp.expand("{{#invoke:test|test}}"), "**")

0 commit comments

Comments
 (0)