Merge pull request #529 from chrox802/chrox802-patch-1

fix a bug about Json::Path
This commit is contained in:
Christopher Dunn 2016-09-07 21:57:56 -05:00 committed by GitHub
commit b063cf4ada

View File

@ -1504,12 +1504,12 @@ void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
index = index * 10 + ArrayIndex(*current - '0');
args_.push_back(index);
}
if (current == end || *current++ != ']')
if (current == end || *++current != ']')
invalidPath(path, int(current - path.c_str()));
} else if (*current == '%') {
addPathInArg(path, in, itInArg, PathArgument::kindKey);
++current;
} else if (*current == '.') {
} else if (*current == '.' || *current == ']') {
++current;
} else {
const char* beginName = current;
@ -1529,7 +1529,7 @@ void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
} else if ((*itInArg)->kind_ != kind) {
// Error: bad argument type
} else {
args_.push_back(**itInArg);
args_.push_back(**itInArg++);
}
}
@ -1544,16 +1544,19 @@ const Value& Path::resolve(const Value& root) const {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
// Error: unable to resolve path (array value expected at position...
return Value::null;
}
node = &((*node)[arg.index_]);
} else if (arg.kind_ == PathArgument::kindKey) {
if (!node->isObject()) {
// Error: unable to resolve path (object value expected at position...)
return Value::null;
}
node = &((*node)[arg.key_]);
if (node == &Value::nullSingleton()) {
// Error: unable to resolve path (object has no member named '' at
// position...)
return Value::null;
}
}
}