Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/json3-response-parsing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"posthog-ruby": patch
"posthog-rails": patch
---

Fix feature flag and remote config response parsing with JSON 3, restoring remote flag evaluation and local definition loading.
2 changes: 1 addition & 1 deletion lib/posthog/feature_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ def _request(uri, request_object, timeout = nil, include_etag: false, retry_stat

# Parse response body to hash
begin
response = JSON.parse(res.body, { symbolize_names: true })
response = JSON.parse(res.body, symbolize_names: true)
# Only add status (and etag if requested) if response is a hash
extra_fields = { status: status_code }
extra_fields[:etag] = etag if include_etag
Expand Down
8 changes: 8 additions & 0 deletions spec/posthog/flags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ module PostHog
JSON.parse(File.read(File.join(__dir__, 'fixtures', 'test-flags-v4.json')), symbolize_names: true)
end
describe '#get_feature_flag' do
it 'parses flag responses with keyword JSON options' do
body = { featureFlags: { 'enabled-flag' => true }, featureFlagPayloads: {} }.to_json
stub_request(:post, flags_endpoint).to_return(status: 200, body: body)
expect(JSON).to receive(:parse).with(body, symbolize_names: true).and_call_original

expect(client.get_feature_flag('enabled-flag', 'test-distinct-id')).to eq(true)
end

it 'calls the $feature_flag_called event with additional properties' do
stub_request(:post, flags_endpoint)
.to_return(status: 200, body: flags_v4_response.to_json)
Expand Down
Loading