Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null string deserialization typecheck fix #2022

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion data/vibe/data/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ struct Json {
private void checkType(TYPES...)(string op = null)
const {
bool matched = false;
foreach (T; TYPES) if (m_type == typeId!T) matched = true;
foreach (T; TYPES) if (m_type == typeId!T || (is(T == string) && m_type == Type.null_)) matched = true;
if (matched) return;

string name;
Expand Down Expand Up @@ -2501,3 +2501,16 @@ private auto trustedRange(R)(R range)
assert(b.foos[0].i == 2);
assert(b.foos[0].foos.length == 0);
}

@safe unittest { // null string deserialization
static struct Foo { @optional string bar; }
auto f = deserializeJson!Foo(`{"bar":null}`);
assert(f.bar is null);

auto j = parseJsonString(`{"bar":null}`);
assert(j["bar"].get!string is null);

auto pv = "bar" in j;
auto v = deserializeJson!string(*pv);
assert(v is null);
}