From 4bd86a20d4e5d492eaf815ca6b1e6d5bf1bd726a Mon Sep 17 00:00:00 2001 From: dairiki Date: Wed, 12 Jul 2000 18:47:53 +0000 Subject: [PATCH] Bug fixes: "[[Link] [Link]", "[SomeLink] [HammondWiki]". git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@160 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- wiki_transform.php3 | 88 ++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/wiki_transform.php3 b/wiki_transform.php3 index 34cf1548d..db3f6642f 100644 --- a/wiki_transform.php3 +++ b/wiki_transform.php3 @@ -1,4 +1,4 @@ - + adds: + * + * Simple sorting doesnt work, since (in ASCII) '[' comes between + * the upper- and lower-case characters. + * + * Using sort "[[Link] [Link]" will come out wrong, using + * rsort "[[link] [link]" will come out wrong. + * (An appropriate usort would work.) + * + * I've added a look-behind assertion to the preg_replace which, + * I think, fixes the problem. I only hope that all PHP versions + * support look-behind assertions.... // sort instead of rsort or "[[link] [link]" will be rendered wrong. sort($brktlinks[0]); reset($brktlinks[0]); + */ for ($i = 0; $i < $numBracketLinks; $i++) { $brktlink = preg_quote($brktlinks[0][$i]); - $linktoken = "${FieldSeparator}brkt${i}brkt${FieldSeparator}"; - $tmpline = preg_replace("|$brktlink|", + $linktoken = $FieldSeparator . $FieldSeparator . ++$ntokens . $FieldSeparator; + /* PS: + * If you're wondering about the double $FieldSeparator, + * consider what happens to (the admittedly sick): + * "[Link1] [Link2]1[Link3]" + * + * Answer: without the double field separator, it gets + * tokenized to "%1% %2%1%3%" (using % to represent $FieldSeparator), + * which will get munged as soon as '%1%' is substituted with it's + * final value. + */ + $tmpline = preg_replace("|(?