Skip to content

Commit

Permalink
Fix a CI_Input::set_cookie() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Feb 1, 2017
1 parent b1780fc commit 422b889
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
16 changes: 7 additions & 9 deletions system/core/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function input_stream($index = NULL, $xss_clean = NULL)
* @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript)
* @return void
*/
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
{
if (is_array($name))
{
Expand Down Expand Up @@ -388,15 +388,13 @@ public function set_cookie($name, $value = '', $expire = '', $domain = '', $path
$path = config_item('cookie_path');
}

if ($secure === FALSE && config_item('cookie_secure') === TRUE)
{
$secure = config_item('cookie_secure');
}
$secure = ($secure === NULL && config_item('cookie_secure') !== NULL)
? (bool) config_item('cookie_secure')
: (bool) $secure;

if ($httponly === FALSE && config_item('cookie_httponly') !== FALSE)
{
$httponly = config_item('cookie_httponly');
}
$httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL)
? (bool) config_item('cookie_httponly')
: (bool) $httponly;

if ( ! is_numeric($expire))
{
Expand Down
2 changes: 1 addition & 1 deletion system/helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* @param bool true makes the cookie accessible via http(s) only (no javascript)
* @return void
*/
function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE, $httponly = FALSE)
function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
{
// Set the config file options
get_instance()->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $httponly);
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Bug fixes for 3.1.4
- Fixed a bug where :doc:`Session Library <libraries/sessions>` didn't read session data in a byte-safe manner when ``mbstring.func_overload`` is enabled.
- Fixed a bug (#4990) - :doc:`Profiler <general/profiling>` didn't close ``<pre>`` tags it generated.
- Fixed a bug (#4990) - :doc:`Profiler <general/profiling>` didn't HTML-escape quotes for ``$_SESSION`` variables.
- Fixed a bug where :doc:`Input Library <libraries/input>` method ``set_cookie()`` didn't allow its *httponly* and *secure* parameters to be overriden to ``FALSE``.

Version 3.1.3
=============
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/helpers/cookie_helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Available Functions
The following functions are available:


.. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])
.. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])
:param mixed $name: Cookie name *or* associative array of all of the parameters available to this function
:param string $value: Cookie value
Expand Down
6 changes: 3 additions & 3 deletions user_guide_src/source/libraries/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Class Reference
This method is identical to ``get()``, ``post()`` and ``cookie()``,
only it fetches the *php://input* stream data.

.. php:method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = FALSE[, $httponly = FALSE]]]]]]])
.. php:method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]])
:param mixed $name: Cookie name or an array of parameters
:param string $value: Cookie value
Expand Down Expand Up @@ -338,8 +338,8 @@ Class Reference
The prefix is only needed if you need to avoid name collisions with
other identically named cookies for your server.

The secure boolean is only needed if you want to make it a secure cookie
by setting it to TRUE.
The *httponly* and *secure* flags, when omitted, will default to your
``$config['cookie_httponly']`` and ``$config['cookie_secure']`` settings.

**Discrete Parameters**

Expand Down

0 comments on commit 422b889

Please sign in to comment.