Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#11620 closed defect (bug) (fixed)

Upload Handling. Use is_numeric instead of ctype_digit.

Reported by: markup's profile markup Owned by:
Milestone: 2.9.1 Priority: high
Severity: normal Version: 2.9
Component: Upload Keywords: has-patch commit
Focuses: Cc:

Description

The function ctype_digit() is used in wp_handle_upload() in /wp-admin/includes/file.php

Please, replace with is_numeric().

Attachments (1)

file.diff (622 bytes) - added by markup 14 years ago.

Download all attachments as: .zip

Change History (11)

@markup
14 years ago

#1 follow-up: @scribu
14 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0
  • Type changed from defect (bug) to enhancement

Could you give a reason why you want this change to be made?

#2 in reply to: ↑ 1 ; follow-up: @markup
14 years ago

  • Cc eval@… added

Replying to scribu:

Could you give a reason why you want this change to be made?

is_numeric() is a standard function for php version 4 and 5, while ctype_digit() is avaliable only in the "ctype" extension, which may have no support at all. In WordPress they refused ctype starting from the version 2.5.1, see for reference http://core.trac.wordpress.org/search?q=ctype_digit

And now if the "ctype" extension is missing on the server, a WP user can't upload media in wordPress through the administration panel. Perhaps you should add this enhancement to 2.9.1 or 2.9.2 milestone.

For those user, that already have the same problem, I propose use the following snippet in the template functions.php

if(!finction_exists('ctype_digit')) {
 function ctype_digit( $num ) { return is_numeric( $num ); }
}

#3 in reply to: ↑ 2 @markup
14 years ago

Replying to markup:

Sorry. This one is correct.

if(!function_exists('ctype_digit')) {
 function ctype_digit( $num ) { return is_numeric( $num ); }
}

#4 @scribu
14 years ago

A very good reason, but I don't think it will make it in 2.9.1.

Knowing the percentage of WP users that don't have the ctype extension would help in determining the severity of the issue.

#5 @scribu
14 years ago

  • Keywords commit added

It seems this has been an issue before: #6534

#6 @nacin
14 years ago

  • Milestone changed from 3.0 to 2.9.1
  • Type changed from enhancement to defect (bug)

This should be 2.9.1, as this was introduced in 2.9 and therefore is a regression from 2.8.

Replying to markup:

if(!function_exists('ctype_digit'))

We would generally add those functions to compat.php. A plugin author could use it without knowing the ramifications, but at the same time, I don't think we currently account for any functions from extensions.

I grepped core and could not find another ctype_* function in use.

#7 @automattor
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12545]) Replace ctype_digit() with is_numeric() for better compatibility, props markup, fixes #11620 for 2.9

#8 @azaozz
14 years ago

And in [12544] for trunk.

#9 @hakre
14 years ago

keep in mind that ctype_digit() does something else than is_numeric(). is_numeric is true for +0123.45e6 or 0xFF.

#10 @azaozz
14 years ago

In this case it only needs to check for numbers 0-8 returned as errors when uploading a file.

Note: See TracTickets for help on using tickets.