Skip to content

Commit

Permalink
Automated rollback of commit c105e85.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 500150564
  • Loading branch information
anandolee authored and Copybara-Service committed Jan 6, 2023
1 parent c105e85 commit de5fae0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 30 deletions.
4 changes: 0 additions & 4 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3334,10 +3334,6 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForValue() {
return value.empty();
},
true);
ExpectSerializeFailureForJson("ValueRejectNanNumberValue", RECOMMENDED,
"optional_value: { number_value: nan}");
ExpectSerializeFailureForJson("ValueRejectInfNumberValue", RECOMMENDED,
"optional_value: { number_value: inf}");
}

void BinaryAndJsonConformanceSuite::RunJsonTestsForAny() {
Expand Down
2 changes: 0 additions & 2 deletions conformance/failure_list_ruby.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOu
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput
Recommended.ValueRejectInfNumberValue.JsonOutput
Recommended.ValueRejectNanNumberValue.JsonOutput
16 changes: 4 additions & 12 deletions java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor.Type;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.OneofDescriptor;
import com.google.protobuf.DoubleValue;
Expand Down Expand Up @@ -965,16 +966,7 @@ private void printValue(MessageOrBuilder message) throws IOException {
throw new InvalidProtocolBufferException("Invalid Value type.");
}
for (Map.Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
FieldDescriptor field = entry.getKey();
if (field.getType() == FieldDescriptor.Type.DOUBLE) {
Double doubleValue = (Double) entry.getValue();
if (doubleValue.isNaN() || doubleValue.isInfinite()) {
throw new IllegalArgumentException(
"google.protobuf.Value cannot encode double values for "
+ "infinity or nan, because they would be parsed as a string.");
}
}
printSingleFieldValue(field, entry.getValue());
printSingleFieldValue(entry.getKey(), entry.getValue());
}
}

Expand Down Expand Up @@ -1691,7 +1683,7 @@ private void mergeMapField(FieldDescriptor field, JsonElement json, Message.Buil
Object key = parseFieldValue(keyField, new JsonPrimitive(entry.getKey()), entryBuilder);
Object value = parseFieldValue(valueField, entry.getValue(), entryBuilder);
if (value == null) {
if (ignoringUnknownFields && valueField.getType() == FieldDescriptor.Type.ENUM) {
if (ignoringUnknownFields && valueField.getType() == Type.ENUM) {
continue;
} else {
throw new InvalidProtocolBufferException("Map value cannot be null.");
Expand Down Expand Up @@ -1732,7 +1724,7 @@ private void mergeRepeatedField(
for (int i = 0; i < array.size(); ++i) {
Object value = parseFieldValue(field, array.get(i), builder);
if (value == null) {
if (ignoringUnknownFields && field.getType() == FieldDescriptor.Type.ENUM) {
if (ignoringUnknownFields && field.getType() == Type.ENUM) {
continue;
} else {
throw new InvalidProtocolBufferException(
Expand Down
12 changes: 0 additions & 12 deletions src/google/protobuf/json/internal/unparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <complex>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -490,17 +489,6 @@ absl::Status WriteValue(JsonWriter& writer, const Msg<Traits>& msg,
if (Traits::GetSize(number_field, msg) > 0) {
auto x = Traits::GetDouble(number_field, msg);
RETURN_IF_ERROR(x.status());
if (std::isnan(*x)) {
return absl::InvalidArgumentError(
"google.protobuf.Value cannot encode double values for nan, "
"because it would be parsed as a string");
}
if (*x == std::numeric_limits<double>::infinity() |
*x == -std::numeric_limits<double>::infinity()) {
return absl::InvalidArgumentError(
"google.protobuf.Value cannot encode double values for "
"infinity, because it would be parsed as a string");
}
writer.Write(*x);
return absl::OkStatus();
}
Expand Down

0 comments on commit de5fae0

Please sign in to comment.