You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "Dmytro Shteflyuk (Jira)" <ji...@apache.org> on 2026/07/19 18:58:00 UTC

[jira] [Updated] (THRIFT-6101) Ruby CompactProtocol should use Ruby truthiness when writing booleans

     [ https://issues.apache.org/jira/browse/THRIFT-6101?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dmytro Shteflyuk updated THRIFT-6101:
-------------------------------------
    Component/s: Ruby - Library

> Ruby CompactProtocol should use Ruby truthiness when writing booleans
> ---------------------------------------------------------------------
>
>                 Key: THRIFT-6101
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6101
>             Project: Thrift
>          Issue Type: Bug
>          Components: Ruby - Library
>            Reporter: Dmytro Shteflyuk
>            Assignee: Dmytro Shteflyuk
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> h3. Problem
> The native and pure-Ruby implementations of {{Thrift::CompactProtocol#write_bool}} interpret values differently.
> The pure-Ruby implementation follows normal Ruby truthiness: only {{false}} and {{nil}} encode as false. The native implementation recognizes only the literal {{true}} as true, so other truthy Ruby values such as {{0}}, {{1}}, and arbitrary objects encode as false.
> h3. Client impact
> Ruby clients can produce different serialized data depending on whether {{thrift_native}} is loaded. A truthy non-boolean value passed through dynamic application code, a wrapper, or a hand-written protocol call is encoded as true in pure-Ruby environments but false in native environments.
> This makes the value placed on the wire dependent on the client’s runtime configuration.
> h3. Reproduction
> {code:ruby}
> require "thrift"
> transport = Thrift::MemoryBufferTransport.new
> protocol = Thrift::CompactProtocol.new(transport)
> protocol.write_bool(0)
> puts transport.read_byte
> {code}
> With {{thrift_native}} loaded, this writes the compact-protocol false marker, {{0x02}}. Without the native extension, it writes the true marker, {{0x01}}, because {{0}} is truthy in Ruby.
> h3. Expected behavior
> Native and pure-Ruby CompactProtocol implementations should follow the same Ruby truthiness semantics. {{false}} and {{nil}} should encode as false; {{true}}, numbers, and other objects should encode as true.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)