From 394a39f82c8063b7c1660faa291200c3d15b783f Mon Sep 17 00:00:00 2001 From: Ash McKenzie Date: Thu, 20 Jun 2019 12:00:51 +0000 Subject: Merge branch '63510-error-parsing-true-boolean-in-gitlab-jsoncache' into 'master' Gitlab::JsonCache#parse_value ensure string Closes #63510 See merge request gitlab-org/gitlab-ce!29885 (cherry picked from commit 788690304a495aa6c4d3e2fa163753f28fbdb82f) 03220c00 Gitlab::JsonCache#parse_value ensure string --- lib/gitlab/json_cache.rb | 2 +- spec/lib/gitlab/json_cache_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/json_cache.rb b/lib/gitlab/json_cache.rb index e4bc437d787..9a0b2b35112 100644 --- a/lib/gitlab/json_cache.rb +++ b/lib/gitlab/json_cache.rb @@ -58,7 +58,7 @@ module Gitlab private def parse_value(raw, klass) - value = ActiveSupport::JSON.decode(raw) + value = ActiveSupport::JSON.decode(raw.to_s) case value when Hash then parse_entry(value, klass) diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb index b82c09af306..c6a6042c65c 100644 --- a/spec/lib/gitlab/json_cache_spec.rb +++ b/spec/lib/gitlab/json_cache_spec.rb @@ -106,6 +106,16 @@ describe Gitlab::JsonCache do expect(cache.read(key)).to be_nil end + context 'when the cached value is a boolean' do + it 'parses the cached value' do + allow(backend).to receive(:read) + .with(expanded_key) + .and_return(true) + + expect(cache.read(key, BroadcastMessage)).to eq(true) + end + end + context 'when the cached value is a hash' do it 'parses the cached value' do allow(backend).to receive(:read) -- cgit v1.2.3