* the percentage symbol (%) and we check whether the value is in the range
* of [0, 100]
* So, we accept two types of input: 1. XX% or 2. XX , 0<=XX<=100
+ * unless the limit parameter is set to false.
*/
-int
-GetPercentage(void)
+double
+GetPercentage(bool limit)
{
char *token = ConfigParser::NextToken();
if (!token) {
- debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: A percentage value is missing.");
+ debugs(3, DBG_CRITICAL, "FATAL: A percentage value is missing.");
self_destruct();
}
int p = xatoi(token);
- if (p < 0 || p > 100) {
- debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: The value '" << token << "' is out of range. A percentage should be within [0, 100].");
+ if (p < 0 || (limit && p > 100)) {
+ debugs(3, DBG_CRITICAL, "FATAL: The value '" << token << "' is out of range. A percentage should be within [0, 100].");
self_destruct();
}
- return p;
+ return static_cast<double>(p) / 100.0;
}
unsigned short
* Parse a percentage value, e.g., 20%.
* The behavior of this function is similar as GetInteger().
* The difference is that the token might contain '%' as percentage symbol (%),
- * and we further check whether the value is in the range of [0, 100]
+ * and we may further check whether the value is in the range of [0, 100].
* For example, 20% and 20 are both valid tokens, while 101%, 101, -1 are invalid.
+ *
+ * \param limit whether to check the value is within 0-100% limit
+ *
+ * \return the percentage as a decimal number. ie 100% = 1.00, 50% = 0.5
*/
-int GetPercentage(void);
+double GetPercentage(bool limit = true);
unsigned short GetShort(void);
min = (time_t) (i * 60); /* convert minutes to seconds */
- i = GetPercentage(); /* token: pct */
-
- pct = (double) i / 100.0;
+ pct = GetPercentage(false); /* token: pct . with no limit on size */
i = GetInteger(); /* token: max */
--- /dev/null
+## Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+#
+# This file contains the list of reported regression cases in 4.0.x parser
+# it covers:
+# refresh_pattern
+
+# pct field parser
+refresh_pattern . 1 1000% 60
+refresh_pattern . 1 0% 60