support-quoted-path-and-required-filds.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --- a/src/google/protobuf/json/internal/parser.cc
  2. +++ b/src/google/protobuf/json/internal/parser.cc
  3. @@ -972,13 +972,29 @@
  4. // Assume approximately six-letter words, so add one extra space for an
  5. // underscore for every six bytes.
  6. snake_path.reserve(path.size() * 7 / 6);
  7. + // Port from protobuf 21.x
  8. + bool is_quoted = false;
  9. + bool is_escaping = false;
  10. for (char c : path) {
  11. + // Outputs quoted string as-is.
  12. + if (is_quoted) {
  13. + snake_path.push_back(c);
  14. + if (is_escaping) {
  15. + is_escaping = false;
  16. + } else if (c == '\\') {
  17. + is_escaping = true;
  18. + } else if (c == '\"') {
  19. + is_quoted = false;
  20. + }
  21. + continue;
  22. + }
  23. if (absl::ascii_isdigit(c) || absl::ascii_islower(c) || c == '.') {
  24. snake_path.push_back(c);
  25. } else if (absl::ascii_isupper(c)) {
  26. snake_path.push_back('_');
  27. snake_path.push_back(absl::ascii_tolower(c));
  28. } else if (lex.options().allow_legacy_syntax) {
  29. + is_quoted = c == '\"';
  30. snake_path.push_back(c);
  31. } else {
  32. return str->loc.Invalid("unexpected character in FieldMask");
  33. @@ -1314,6 +1330,9 @@
  34. s = absl::InvalidArgumentError(
  35. "extraneous characters after end of JSON object");
  36. }
  37. + if (s.ok() && !message->IsInitialized()) {
  38. + s = absl::InvalidArgumentError("Not all fileds are sets");
  39. + }
  40. PROTOBUF_DLOG(INFO) << "json2/status: " << s;
  41. PROTOBUF_DLOG(INFO) << "json2/output: " << message->DebugString();