Anonymous user
Module:Mapframe: Difference between revisions
better regex to match description key (handles N>9)
Richardpruen (talk | contribs) m (1 revision imported: Template for journal ) |
(better regex to match description key (handles N>9)) |
||
Line 191: | Line 191: | ||
local cleanArgs = {} | local cleanArgs = {} | ||
for key, val in pairs(argsTable) do | for key, val in pairs(argsTable) do | ||
if type(val) == 'string' then | if type(key) == 'string' and type(val) == 'string' then | ||
val = val:match('^%s*(.-)%s*$') | val = val:match('^%s*(.-)%s*$') | ||
if val ~= '' then | if val ~= '' then | ||
-- control characters inside json need to be escaped, but stripping them is simpler | -- control characters inside json need to be escaped, but stripping them is simpler | ||
-- See also T214984 | -- See also T214984 | ||
-- However, *don't* strip control characters from wikitext or you'll break strip markers | -- However, *don't* strip control characters from wikitext (text or description parameters) or you'll break strip markers | ||
-- Alternatively it might be better to only strip control char from raw parameter content | |||
if util.matchesParam('text', key) or util.matchesParam('description', key, key:gsub('^%D+(%d+)$', '%1') ) then | |||
cleanArgs[key] = val | |||
else | |||
cleanArgs[key] = val:gsub('%c',' ') | |||
end | |||
end | end | ||
else | else |