diff -u b/core/misc/jquery.cookie.shim.es6.js b/core/misc/jquery.cookie.shim.es6.js --- b/core/misc/jquery.cookie.shim.es6.js +++ b/core/misc/jquery.cookie.shim.es6.js @@ -48,7 +48,9 @@ try { value = decodeURIComponent(value.replace(/\+/g, ' ')); return parseJson ? JSON.parse(value) : value; - } catch (e) {} + } catch (e) { + // Exceptions on JSON parsing should be ignored. + } }; /** @@ -170,7 +172,20 @@ ), }); - return key === undefined ? cookiesShim.get() : cookiesShim.get(key); + return (() => { + if (key === undefined) { + const results = cookiesShim.get(); + Object.keys(results).forEach(resultKey => { + if (results[resultKey] === undefined) { + delete results[resultKey]; + } + }); + + return results; + } + + return cookiesShim.get(key); + })(); }; /** diff -u b/core/misc/jquery.cookie.shim.js b/core/misc/jquery.cookie.shim.js --- b/core/misc/jquery.cookie.shim.js +++ b/core/misc/jquery.cookie.shim.js @@ -69,7 +69,19 @@ return reader(cookieValue, cookieName, userProvidedConverter, $.cookie.raw, $.cookie.json); } }); - return key === undefined ? cookiesShim.get() : cookiesShim.get(key); + return function () { + if (key === undefined) { + var results = cookiesShim.get(); + Object.keys(results).forEach(function (resultKey) { + if (results[resultKey] === undefined) { + delete results[resultKey]; + } + }); + return results; + } + + return cookiesShim.get(key); + }(); }; $.cookie.defaults = _objectSpread({ reverted: --- b/core/tests/Drupal/Nightwatch/Tests/jsCookieTest.js +++ a/core/tests/Drupal/Nightwatch/Tests/jsCookieTest.js @@ -222,7 +222,6 @@ { js_cookie_test_first: 'red panda', js_cookie_test_second: 'second red panda', - js_cookie_test_third: undefined, }, '$.cookie() returns object containing all cookies', );