Skip to content

Commit

Permalink
Add support for static array in registerWebInterface and disallow boo…
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Oct 9, 2015
1 parent 3bd96e3 commit 92f4ae0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/vibe/web/common.d
Expand Up @@ -651,6 +651,9 @@ package ParamResult readFormParamRec(T)(scope HTTPServerRequest req, ref T dst,

static if (isDynamicArray!T && !isSomeString!T) {
alias EL = typeof(T.init[0]);
static assert(!is(EL == bool),
"Boolean arrays are not allowed, because their length cannot " ~
"be uniquely determined. Use a static array instead.");
size_t idx = 0;
dst = T.init;
while (true) {
Expand All @@ -661,6 +664,12 @@ package ParamResult readFormParamRec(T)(scope HTTPServerRequest req, ref T dst,
dst ~= el;
idx++;
}
} else static if (isStaticArray!T) {
foreach (i; 0 .. T.length) {
auto r = readFormParamRec(req, dst[i], format("%s_%s", fieldname, i), true, err);
if (r == ParamResult.error) return r;
assert(r != ParamResult.skipped); break;
}
} else static if (isNullable!T) {
typeof(dst.get()) el = void;
auto r = readFormParamRec(req, el, fieldname, false, err);
Expand Down Expand Up @@ -728,3 +737,8 @@ package void setVoid(T, U)(ref T dst, U value)
}
} else dst = value;
}

unittest {
static assert(!__traits(compiles, { bool[] barr; ParamError err;readFormParamRec(null, barr, "f", true, err); }));
static assert(__traits(compiles, { bool[2] barr; ParamError err;readFormParamRec(null, barr, "f", true, err); }));
}

0 comments on commit 92f4ae0

Please sign in to comment.