Skip to content

Commit 4d3e4c2

Browse files
committed
docs: add documentation
1 parent a09683d commit 4d3e4c2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

user_guide_src/source/changelogs/v4.2.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Behavior Changes
1616
================
1717

1818
- Guessing the file extension from the MIME type has been changed if the proposed extension is not valid. Previously, the guessing will early terminate and return ``null``. Now, if a proposed extension is given and is invalid, the MIME guessing will continue checking using the mapping of extension to MIME types.
19+
- If there is a cookie with a prefixed name and a cookie with the same name without a prefix, the previous ``get_cookie()`` had the tricky behavior of returning the cookie without the prefix. Now the behavior has been fixed as a bug, and has been changed. See :ref:`Upgrading <upgrade-421-get_cookie>` for details.

user_guide_src/source/helpers/cookie_helper.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,24 @@ The following functions are available:
3939
a description of its use, as this function is an alias for
4040
:php:func:`Response::setCookie() <setCookie>`.
4141

42-
.. php:function:: get_cookie($index[, $xssClean = false])
42+
.. php:function:: get_cookie($index[, $xssClean = false[, $prefix = '']])
4343
4444
:param string $index: Cookie name
4545
:param bool $xssClean: Whether to apply XSS filtering to the returned value
46+
:param string|null $prefix: Cookie name prefix. If set to ``''``, the default value from **app/Config/Cookie.php** will be used. If set to ``null``, no prefix
4647
:returns: The cookie value or null if not found
4748
:rtype: mixed
4849

50+
.. note:: Since v4.2.1, the third parameter ``$prefix`` has been introduced and the behavior has been changed a bit due to a bug fix. See :ref:`Upgrading <upgrade-421-get_cookie>` for details.
51+
4952
This helper function gives you friendlier syntax to get browser
5053
cookies. Refer to the :doc:`IncomingRequest Library </incoming/incomingrequest>` for
5154
detailed description of its use, as this function acts very
5255
similarly to ``IncomingRequest::getCookie()``, except it will also prepend
5356
the ``Config\Cookie::$prefix`` that you might've set in your
5457
**app/Config/Cookie.php** file.
5558

56-
.. warning:: Using XSS filtering is a bad practice. It does not prevent XSS attacks perfectly. Using ``esc()`` with the correct ``$context`` in the views is recommended.
59+
.. warning:: Using XSS filtering is a bad practice. It does not prevent XSS attacks perfectly. Using ``esc()`` with the correct ``$context`` in the views is recommended.
5760

5861
.. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])
5962

user_guide_src/source/installation/upgrade_421.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,41 @@ app/Config/Mimes.php
2323
Breaking Changes
2424
****************
2525

26+
.. _upgrade-421-get_cookie:
27+
28+
get_cookie()
29+
============
30+
31+
If there is a cookie with a prefixed name and a cookie with the same name without a prefix, the previous ``get_cookie()`` had the tricky behavior of returning the cookie without the prefix.
32+
33+
For example, when ``Config\Cookie::$prefix`` is ``prefix_``, there are two cookies, ``test`` and ``prefix_test``:
34+
35+
.. code-block:: php
36+
37+
$_COOKIES = [
38+
'test' => 'Non CI Cookie',
39+
'prefix_test' => 'CI Cookie',
40+
];
41+
42+
Previously, ``get_cookie()`` returns the following:
43+
44+
.. code-block:: php
45+
46+
get_cookie('test'); // returns "Non CI Cookie"
47+
get_cookie('prefix_test'); // returns "CI Cookie"
48+
49+
Now the behavior has been fixed as a bug, and has been changed like the following.
50+
51+
.. code-block:: php
52+
53+
get_cookie('test'); // returns "CI Cookie"
54+
get_cookie('prefix_test'); // returns null
55+
get_cookie('test', false, null); // returns "Non CI Cookie"
56+
57+
If you depend on the previous behavior, you need to change your code.
58+
59+
.. note:: In the example above, if there is only one cookie ``prefix_test``,
60+
the previous ``get_cookie('test')`` also returns ``"CI Cookie"``.
2661

2762
Breaking Enhancements
2863
*********************

0 commit comments

Comments
 (0)