googleapis / googleapis/google-cloud-swift

Value JSON Decoding Misclassifies String "true" and "false" as Boolean

Closed Beginner friendly
#917 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
26
Forks
10
Avg merge
12h 57m
Merged PRs (30d)
213

Description

## Location
- [pkgs/swift-google-wkt/Sources/GoogleCloudWKT/Value.swift:L91-L96](file:///usr/local/google/home/coryan/google-cloud-swift/pkgs/swift-google-wkt/Sources/GoogleCloudWKT/Value.swift#L91-L96)
- [pkgs/swift-google-wkt/Sources/GoogleCloudWKT/ProtoJSONDecoder.swift:L110-L124](file:///usr/local/google/home/coryan/google-cloud-swift/pkgs/swift-google-wkt/Sources/GoogleCloudWKT/ProtoJSONDecoder.swift#L110-L124)

## Description
When decoding a `Value` using `_ProtoJSONDecoder`, JSON strings with the literal values `"true"` or `"false"` are incorrectly decoded into `Value.bool(true)` or `Value.bool(false)` rather than `Value.string("true")` / `Value.string("false")`.

This occurs because `Value.init(from: decoder)` attempts `container.decode(Bool.self)` before `container.decode(String.self)`. In `_ProtoJSONDecoder`, `InternalSingleValueContainer.decode(Bool.self)` coerces the string values `"true"` and `"false"` to booleans to support proto relaxed numeric/boolean JSON parsing. As a result, string values in JSON dynamically typed structures lose their type fidelity.

## Steps to Reproduce / Verification
Decode a `Value` containing the JSON string `"true"` via `_ProtoJSONDecoder`:
```swift
struct Wrapped: Codable, Equatable {
let value: Value
}
let json = Data(#"{"value": "true"}"#.utf8)
let decoded = try _ProtoJSONDecoder().decode(Wrapped.self, from: json)
#expect(decoded.value == .string("true")) // Fails: received .bool(true)
```

Contributor guide

Open the contributing guide

Research direction

Start with Value.swift lines 91-96 and ProtoJSONDecoder.swift lines 110-124, then run the reproduction using _ProtoJSONDecoder. Add regression coverage for JSON strings "true" and "false" and verify they decode as Value.string rather than Value.bool.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.