svn path=/trunk/; revision=50
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014 - 2017 Paul Hänsch
#
# This file is part of shcgi.
#
#
# This file is part of shcgi.
#
validate(){
# print value if value matches regex; otherwise print default
value="$1"
validate(){
# print value if value matches regex; otherwise print default
value="$1"
- regex="$(printf %s\\n "$2" | sed -r ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')"
- # ^^ escape only unescaped slash characters for later insertion
- printf %s\\n "${value}" \
- | sed -rn "2q; /^(${regex})\$/{p;q}; a${default}
- "
+ printf %s "${value%%${BR}*}" |grep -xE "$regex" || printf %s "$default"
}
invalidate(){
# print default if value matches regex; otherwise print value
value="$1"
}
invalidate(){
# print default if value matches regex; otherwise print value
value="$1"
- regex="$(printf %s\\n "$2" | sed -r ':X;s;(^|[^\\])((\\\\)*)/;\1\2\\/;g;tX')"
- # ^^ escape only unescaped slash characters for later insertion
-
- printf %s\\n "${value}" \
- | sed -rn "2q; /^(${regex})\$/{bX}; p;q; :X;a${default}
- "
+
+ printf %s "${value%%${BR}*}" |grep -qxE "$regex" && printf %s "$default" || printf %s "${value%%${BR}*}"