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