php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70453 IntlChar::foldCase() incorrect arguments and missing constants
Submitted: 2015-09-07 20:11 UTC Modified: 2015-09-09 23:39 UTC
From: colinodell@php.net Assigned: cmb (profile)
Status: Closed Package: intl (PECL)
PHP Version: 7.0.0RC2 OS:
Private report: No CVE-ID: None
 [2015-09-07 20:11 UTC] colinodell@php.net
Description:
------------
There are multiple issues with the IntlChar::foldCase() implementation:

1. The parameters defined in lines 421 - 423 (https://github.com/php/php-src/blob/master/ext/intl/uchar/uchar.c#L421) don't match the intended method signature (it should reflect line 420).
2. The default value for the second parameter is IntlChar::FOLD_CASE_DEFAULT. However, this constant is not defined.
3. The other possible constant U_FOLD_CASE_EXCLUDE_SPECIAL_I () is also missing.

I'm not a C programmer, but I think these changes should resolve the issue (you'll definitely want to double-check and test these of course):

1. Replace lines 421 - 423 with something like this:

ZEND_BEGIN_ARG_INFO_EX(foldCase_arginfo, 0, ZEND_RETURN_VALUE, 1)
	ZEND_ARG_INFO(0, codepoint)
	ZEND_ARG_INFO(1, options)
ZEND_END_ARG_INFO();

2. Define the following two constants:

  IntlChar::FOLD_CASE_DEFAULT = 0
  IntlChar::FOLD_CASE_EXCLUDE_SPECIAL_I = 1

These are the same names and values used by HHVM's implementation.  The values also match what's used by the underlying ICU library: https://ssl.icu-project.org/apiref/icu4c/uchar_8h.html#a7c41915be9809fd815a5c7d581ad1ea3

Test script:
---------------
See https://3v4l.org/2gk3o or run this yourself:

<?php
var_dump(IntlChar::FOLD_CASE_DEFAULT);
var_dump(IntlChar::FOLD_CASE_EXCLUDE_SPECIAL_I);

Expected result:
----------------
int(0)
int(1)

Actual result:
--------------
Fatal error: Uncaught Error: Undefined class constant 'FOLD_CASE_DEFAULT' in /in/2gk3o:2
Stack trace:
#0 {main}
  thrown in /in/2gk3o on line 2

Process exited with code 255.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-07 20:38 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2015-09-07 20:43 UTC] colinodell@php.net
Just wanted to reiterate that my first suggestion is probably not 100% correct, especially since I don't fully those macros.  Basically the first argument should be referred to as "$codepoint" in the userland docs (which I'm working on) and should be required.  The second param "$options" should be optional.

Hope that makes sense.
 [2015-09-07 21:07 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1372909429b2f54bdab80f9599c17ccf6e456f08
Log: Fix #70453: IntlChar::foldCase() incorrect arguments and missing constants
 [2015-09-07 21:07 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-09-07 21:14 UTC] cmb@php.net
-Status: Closed +Status: Feedback
 [2015-09-07 21:14 UTC] cmb@php.net
I was a bit fast, it seems. :) I had not changed the first
parameter $foldCase, what should of course be done. I'm not sure,
however, whether $char or $codepoint is more appropriate. It seems
that $char is used for nearly all other methods.

BTW: the first parameter to ZEND_ARG_INFO states whether the
parameter is passed by reference.
 [2015-09-07 22:50 UTC] colinodell@php.net
> I'm not sure, however, whether $char or $codepoint is more appropriate.
> It seems that $char is used for nearly all other methods.

Sorry, it looks like $char is used in the proto lines, and "codepoint" is used in the ZEND_ARG_INFO() lines.  Perhaps we can follow the same pattern here?

> BTW: the first parameter to ZEND_ARG_INFO states whether the
> parameter is passed by reference.

Oh nifty!  I appreciate the info :)
 [2015-09-07 23:24 UTC] cmb@php.net
-Status: Feedback +Status: Verified
 [2015-09-07 23:24 UTC] cmb@php.net
> Sorry, it looks like $char is used in the proto lines, and
> "codepoint" is used in the ZEND_ARG_INFO() lines.

Good catch! It doesn't make sense to me to have $char in the proto
line, but "codepoint" in the ARG_INFO and in the documentation. If
there are no objections, I'll change all protos in
ext/intl/uchar/uchar.c to $codepoint also.
 [2015-09-08 00:20 UTC] colinodell@php.net
> If there are no objections, I'll change all protos
> in ext/intl/uchar/uchar.c to $codepoint also.

That sounds good to me - no objections here!
 [2015-09-09 23:39 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2015-09-15 12:13 UTC] ab@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1372909429b2f54bdab80f9599c17ccf6e456f08
Log: Fix #70453: IntlChar::foldCase() incorrect arguments and missing constants
 [2016-07-20 11:36 UTC] davey@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1372909429b2f54bdab80f9599c17ccf6e456f08
Log: Fix #70453: IntlChar::foldCase() incorrect arguments and missing constants
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 01:01:27 2024 UTC