SourceForge logo
SourceForge logo
Menu

phpwiki-checkins

From: Geoffrey T. D. <da...@us...> - 2002年09月18日 15:17:15
Update of /cvsroot/phpwiki/phpwiki/lib
In directory usw-pr-cvs1:/tmp/cvs-serv12104/lib
Modified Files:
	stdlib.php 
Log Message:
New function MangleXmlIdentifier() used to ensure that the ids used
for named anchors (fragment identifiers) are valid XML fragment
identifiers ([A-Za-z][A-Za-z0-9:._-]*).
Index: stdlib.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/stdlib.php,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -2 -b -p -d -r1.125 -r1.126
--- stdlib.php	17 Sep 2002 19:23:32 -0000	1.125
+++ stdlib.php	18 Sep 2002 15:17:12 -0000	1.126
@@ -42,4 +42,37 @@
 */
 
+/**
+ * Convert string to a valid XML identifier.
+ *
+ * XML 1.0 identifiers are of the form: [A-Za-z][A-Za-z0-9:_.-]*
+ *
+ * We would like to have, e.g. named anchors within wiki pages
+ * names like "Table of Contents" --- clearly not a valid XML
+ * fragment identifier.
+ *
+ * This function implements a one-to-one map from {any string}
+ * to {valid XML identifiers}.
+ *
+ * It does this by
+ * converting all bytes not in [A-Za-z0-9:_-],
+ * and any leading byte not in [A-Za-z] to 'xbb.',
+ * where 'bb' is the hexadecimal representation of the
+ * character.
+ *
+ * As a special case, the empty string is converted to 'empty.'
+ *
+ * @param string $str
+ * @return string
+ */
+function MangleXmlIdentifier($str) 
+{
+ if (!$str)
+ return 'empty.';
+ 
+ return preg_replace('/[^-_:A-Za-z0-9]|(?<=^)[^A-Za-z]/e',
+ "'x' . sprintf('%02x', ord('\0円')) . '.'",
+ $str);
+}
+ 
 
 function WikiURL($pagename, $args = '', $get_abs_url = false) {
@@ -83,5 +116,5 @@ function WikiURL($pagename, $args = '', 
 }
 if ($anchor)
- $url .= "#$anchor";
+ $url .= "#" . MangleXmlIdentifier($anchor);
 return $url;
 }
@@ -346,5 +379,6 @@ function LinkBracketLink($bracketlink) {
 if ($hash) {
 // It's an anchor, not a link...
- return HTML::a(array('name' => $link, 'id' => $link),
+ $id = MangleXmlIdentifier($link);
+ return HTML::a(array('name' => $id, 'id' => $id),
 $bar ? $label : $link);
 }
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /