Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle escaped question marks properly in python text-format. #19648

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions conformance/conformance_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ static TestStatus FormatFailureMessage(const TestStatus& input) {
// Remove newlines
Normalize(formatted_failure_message);
// Truncate failure message if needed
if (formatted_failure_message.length() > 128) {
formatted_failure_message = formatted_failure_message.substr(0, 128);
if (formatted_failure_message.length() > 300) {
formatted_failure_message = formatted_failure_message.substr(0, 300);
}
TestStatus properly_formatted;
properly_formatted.set_name(input.name());
Expand Down Expand Up @@ -303,8 +303,8 @@ std::string ConformanceTestSuite::ConformanceRequestSetting::OutputFormatString(
}

void ConformanceTestSuite::TruncateDebugPayload(string* payload) {
if (payload != nullptr && payload->size() > 200) {
payload->resize(200);
if (payload != nullptr && payload->size() > 500) {
payload->resize(500);
payload->append("...(truncated)");
}
}
Expand Down
4 changes: 0 additions & 4 deletions conformance/text_format_failure_list_python.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# TODO: These should be fixed.
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
Required.*.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\

# Optional float interpreted as `inf`
Required.*.TextFormatInput.FloatFieldMaxValue.ProtobufOutput # Output was not equivalent to reference message
Expand Down
4 changes: 0 additions & 4 deletions conformance/text_format_failure_list_python_cpp.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
Required.*.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
4 changes: 0 additions & 4 deletions conformance/text_format_failure_list_python_upb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@
# TODO: These should be fixed.
Required.*.TextFormatInput.FloatFieldNoNegativeOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.FloatFieldNoOctal # Should have failed to parse, but didn't.
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput # Output was not equivalent to reference message: modified: optional_bytes: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\t
Required.*.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
Required.*.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput # Output was not equivalent to reference message: modified: optional_string: "\007\010\014\n\r\t\013?\\\'\"" -> "\007\010\014\n\r\
3 changes: 3 additions & 0 deletions python/google/protobuf/text_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def ReplaceHex(m):
# allow single-digit hex escapes (like '\xf').
result = _CUNESCAPE_HEX.sub(ReplaceHex, text)

# Special handling due to C++ trigraphs :(.
result = result.replace('\\?', '?')

# Replaces Unicode escape sequences with their character equivalents.
result = result.encode('raw_unicode_escape').decode('raw_unicode_escape')
# Encode Unicode characters as UTF-8, then decode to Latin-1 escaping
Expand Down
Loading