Skip to content

Commit a8dce31

Browse files
committed
Added the 'add_slashes' sanitization filter (FILTER_SANITIZE_ADD_SLASHES) as an alias to 'magic_quotes' (FILTER_SANITIZE_MAGIC_QUOTES) so we can move past our "magical" legacy.
1 parent 1c01b1a commit a8dce31

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
type 37). (Peter Kokot)
88

99
- Filter:
10+
. Added the 'add_slashes' sanitization mode (FILTER_SANITIZE_ADD_SLASHES).
11+
(Kalle)
1012
. Fixed bug #76366 (References in sub-array for filtering breaks the filter).
1113
(ZiHang Gao)
1214

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ JSON:
374374
. FILTER_VALIDATE_FLOAT now also supports a `thousand` option, which
375375
defines the set of allowed thousand separator chars. The default (`"',."`)
376376
is fully backward compatible with former PHP versions.
377+
. FILTER_SANITIZE_ADD_SLASHES has been added as an alias of the 'magic_quotes'
378+
filter (FILTER_SANITIZE_MAGIC_QUOTES). The 'magic_quotes' filter is subject
379+
to removal in future versions of PHP.
377380

378381
FTP:
379382
. Set default transfer mode to binary

ext/filter/filter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static const filter_list_entry filter_list[] = {
5858
{ "url", FILTER_SANITIZE_URL, php_filter_url },
5959
{ "number_int", FILTER_SANITIZE_NUMBER_INT, php_filter_number_int },
6060
{ "number_float", FILTER_SANITIZE_NUMBER_FLOAT, php_filter_number_float },
61-
{ "magic_quotes", FILTER_SANITIZE_MAGIC_QUOTES, php_filter_magic_quotes },
61+
{ "magic_quotes", FILTER_SANITIZE_MAGIC_QUOTES, php_filter_add_slashes },
62+
{ "add_slashes", FILTER_SANITIZE_ADD_SLASHES, php_filter_add_slashes },
6263

6364
{ "callback", FILTER_CALLBACK, php_filter_callback },
6465
};
@@ -253,6 +254,7 @@ PHP_MINIT_FUNCTION(filter)
253254
REGISTER_LONG_CONSTANT("FILTER_SANITIZE_NUMBER_INT", FILTER_SANITIZE_NUMBER_INT, CONST_CS | CONST_PERSISTENT);
254255
REGISTER_LONG_CONSTANT("FILTER_SANITIZE_NUMBER_FLOAT", FILTER_SANITIZE_NUMBER_FLOAT, CONST_CS | CONST_PERSISTENT);
255256
REGISTER_LONG_CONSTANT("FILTER_SANITIZE_MAGIC_QUOTES", FILTER_SANITIZE_MAGIC_QUOTES, CONST_CS | CONST_PERSISTENT);
257+
REGISTER_LONG_CONSTANT("FILTER_SANITIZE_ADD_SLASHES", FILTER_SANITIZE_ADD_SLASHES, CONST_CS | CONST_PERSISTENT);
256258

257259
REGISTER_LONG_CONSTANT("FILTER_CALLBACK", FILTER_CALLBACK, CONST_CS | CONST_PERSISTENT);
258260

ext/filter/filter_private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
#define FILTER_SANITIZE_NUMBER_FLOAT 0x0208
8686
#define FILTER_SANITIZE_MAGIC_QUOTES 0x0209
8787
#define FILTER_SANITIZE_FULL_SPECIAL_CHARS 0x020a
88-
#define FILTER_SANITIZE_LAST 0x020a
88+
#define FILTER_SANITIZE_ADD_SLASHES 0x020b
89+
#define FILTER_SANITIZE_LAST 0x020b
8990

9091
#define FILTER_SANITIZE_ALL 0x0200
9192

ext/filter/php_filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void php_filter_email(PHP_INPUT_FILTER_PARAM_DECL);
9191
void php_filter_url(PHP_INPUT_FILTER_PARAM_DECL);
9292
void php_filter_number_int(PHP_INPUT_FILTER_PARAM_DECL);
9393
void php_filter_number_float(PHP_INPUT_FILTER_PARAM_DECL);
94-
void php_filter_magic_quotes(PHP_INPUT_FILTER_PARAM_DECL);
94+
void php_filter_add_slashes(PHP_INPUT_FILTER_PARAM_DECL);
9595

9696
void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL);
9797

ext/filter/sanitizing_filters.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,11 @@ void php_filter_number_float(PHP_INPUT_FILTER_PARAM_DECL)
368368
}
369369
/* }}} */
370370

371-
/* {{{ php_filter_magic_quotes */
372-
void php_filter_magic_quotes(PHP_INPUT_FILTER_PARAM_DECL)
371+
/* {{{ php_filter_add_slashes */
372+
void php_filter_add_slashes(PHP_INPUT_FILTER_PARAM_DECL)
373373
{
374+
/* This filter is used by both 'add_slashes' & 'magic_quotes' (legacy) */
375+
374376
zend_string *buf;
375377

376378
/* just call php_addslashes quotes */

ext/filter/tests/008.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var_dump(filter_list(array()));
1111
echo "Done\n";
1212
?>
1313
--EXPECTF--
14-
array(21) {
14+
array(22) {
1515
[0]=>
1616
string(3) "int"
1717
[1]=>
@@ -53,6 +53,8 @@ array(21) {
5353
[19]=>
5454
string(12) "magic_quotes"
5555
[20]=>
56+
string(11) "add_slashes"
57+
[21]=>
5658
string(8) "callback"
5759
}
5860

ext/filter/tests/033.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ url PHP 1 foo@bar.com http://a.b.c 1.2.3.4 123 12
3030
number_int 1 1234 123 123
3131
number_float 1 1234 123 123
3232
magic_quotes PHP 1 foo@bar.com http://a.b.c 1.2.3.4 123 123abc<>() O\'Henry 하퍼 aa:bb:cc:dd:ee:ff
33+
add_slashes PHP 1 foo@bar.com http://a.b.c 1.2.3.4 123 123abc<>() O\'Henry 하퍼 aa:bb:cc:dd:ee:ff
3334
callback PHP 1 FOO@BAR.COM HTTP://A.B.C 1.2.3.4 123 123ABC<>() O'HENRY 하퍼 AA:BB:CC:DD:EE:FF

0 commit comments

Comments
 (0)