Skip to content

Commit

Permalink
Check for trailing characters when parsing std::string.
Browse files Browse the repository at this point in the history
  • Loading branch information
greggomann committed Oct 11, 2015
1 parent cc130fb commit a6dac31
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion picojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,12 @@ namespace picojson {

inline std::string parse(value& out, const std::string& s) {
std::string err;
parse(out, s.begin(), s.end(), &err);
std::string::const_iterator begin = s.begin();
std::string::const_iterator last_char = begin + s.find_last_not_of(" \t\n\r");
std::string::const_iterator end = parse(out, begin, s.end(), &err);
if (end != last_char + 1 && err.empty()) {
err = "Input string contained non-whitespace trailing characters.";
}
return err;
}

Expand Down

0 comments on commit a6dac31

Please sign in to comment.