[Fusionforge-commits] r8472 - trunk/gforge/common/include

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Tue Dec 8 13:26:31 CET 2009


Author: aljeux
Date: 2009-12-08 13:26:31 +0100 (Tue, 08 Dec 2009)
New Revision: 8472

Modified:
   trunk/gforge/common/include/escapingUtils.php
Log:
New getFilteredStringFromRequest() to filter args against a perl regexp

Modified: trunk/gforge/common/include/escapingUtils.php
===================================================================
--- trunk/gforge/common/include/escapingUtils.php	2009-12-08 12:26:26 UTC (rev 8471)
+++ trunk/gforge/common/include/escapingUtils.php	2009-12-08 12:26:31 UTC (rev 8472)
@@ -353,6 +353,23 @@
 	return strtr($string, array_flip($htmlTranslationTable));
 }
 
+/**
+ * getFilteredStringFromRequest - get a string from REQUEST
+ *
+ * @param string $key key of the wanted value
+ * @param string $pattern Regular expression of allowed values.
+ * @param string $defaultValue if we can't find the wanted value, it returns the default value
+ * @return string the value or false if not valid.
+ */
+function getFilteredStringFromRequest($string, $pattern, $defaultValue = '') {
+	$value = getStringFromRequest($string, $defaultValue);
+	if (preg_match($pattern, $value)) {
+		return $value;
+	} else {
+		return $defaultValue;
+	}
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list