Skip to content

[Ruby] Decoding JSON raises ParseError on Windows #5884

@blowmage

Description

@blowmage

What version of protobuf and what language are you using?

Version: v3.7.0
Language: Ruby

What operating system (Linux, Windows, ...) and version?

Windows 10

What runtime / compiler are you using (e.g., python version or gcc version)

Ruby 2.6.1

What did you do?

Install latest google-cloud-pubsub and google-protobuf gems, and run this code:

require "google/cloud/pubsub/v1"

now = Time.now
now_ts = Google::Protobuf::Timestamp.new seconds: now.to_i, nanos: now.nsec
msg = Google::Cloud::PubSub::V1::PubsubMessage.new publish_time: now_ts

msg.to_json #=> "{\"attributes\":{},\"publishTime\":\"2019-03-13T15:40:43.729054800Z\"}"

decoded_msg = Google::Cloud::PubSub::V1::PubsubMessage.decode_json msg.to_json
#=> Traceback (most recent call last):
#           1: from pubsub.rb:9:in `<main>'
#   pubsub.rb:9:in `decode_json': Error occurred during parsing: error parsing timestamp: mingw doesn't support strptime (Google::Protobuf::ParseError)

What did you expect to see

The ability to create a new protobuf resource object by decoding JSON that contains a timestamp.

What did you see instead?

A Google::Protobuf::ParseError error.

Anything else we should know about your project / environment

This appears to only happen on Windows, and it looks intentional. But Ruby will parse the timestamp string without issue, so I don't see why Windows couldn't use Time.parse instead of strptime.

require "time"

time_obj = Time.parse "2019-03-13T15:40:43.729054800Z"
timestamp_obj = Google::Protobuf::Timestamp.new seconds: time_obj.to_i, nanos: time_obj.nsec

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions