Improve mw.text.nowiki, part 2

The following are now correctly escaped:
* Blank lines (including those with only tabs)
* ---- at the start of a line

Bug: 53658
Change-Id: Ib000ff4f21f76c310741de89de0e0b66f6450344
This commit is contained in:
Brad Jorsch 2013-09-20 13:17:38 -04:00
parent 32bb3e21f2
commit a0a1b05b74

View file

@ -106,6 +106,9 @@ local nowikiRepl2 = {
["\n:"] = "\n:", ["\r:"] = "\r:", ["\n:"] = "\n:", ["\r:"] = "\r:",
["\n;"] = "\n&#59;", ["\r;"] = "\r&#59;", ["\n;"] = "\n&#59;", ["\r;"] = "\r&#59;",
["\n "] = "\n ", ["\r "] = "\r ", ["\n "] = "\n ", ["\r "] = "\r ",
["\n\n"] = "\n
", ["\r\n"] = "
\n",
["\n\r"] = "\n
", ["\r\r"] = "\r
",
["\n\t"] = "\n	", ["\r\t"] = "\r	",
} }
local nowikiReplMagic = {} local nowikiReplMagic = {}
@ -124,7 +127,10 @@ end
function mwtext.nowiki( s ) function mwtext.nowiki( s )
-- string.gsub is safe here, because we're only caring about ASCII chars -- string.gsub is safe here, because we're only caring about ASCII chars
s = string.gsub( s, '["&\'<=>%[%]{|}]', nowikiRepl1 ) s = string.gsub( s, '["&\'<=>%[%]{|}]', nowikiRepl1 )
s = string.sub( string.gsub( '\n' .. s, '[\r\n][#*:; ]', nowikiRepl2 ), 2 ) s = '\n' .. s
s = string.gsub( s, '[\r\n][#*:; \n\r\t]', nowikiRepl2 )
s = string.gsub( s, '([\r\n])%-%-%-%-', '%1&#45;---' )
s = string.sub( s, 2 )
s = string.gsub( s, '__', '_&#95;' ) s = string.gsub( s, '__', '_&#95;' )
s = string.gsub( s, '://', '&#58;//' ) s = string.gsub( s, '://', '&#58;//' )
s = string.gsub( s, 'ISBN%s', nowikiReplMagic ) s = string.gsub( s, 'ISBN%s', nowikiReplMagic )