@@ -4815,28 +4815,65 @@ static inline char* php_mb_chr(zend_long cp, const char* enc, size_t *output_len
4815
4815
}
4816
4816
}
4817
4817
4818
- if (php_mb_is_no_encoding_unicode (no_enc )) {
4819
4818
4820
- if (0 > cp || 0x10ffff < cp ) {
4819
+ if (php_mb_is_no_encoding_utf8 ( no_enc ) ) {
4821
4820
4822
- if (php_mb_is_no_encoding_unicode (MBSTRG (current_internal_encoding )-> no_encoding )) {
4821
+ if (0 > cp || cp > 0x10ffff || (cp > 0xd7ff && 0xe000 > cp )) {
4822
+ if (php_mb_is_no_encoding_utf8 (MBSTRG (current_internal_encoding )-> no_encoding )) {
4823
4823
cp = MBSTRG (current_filter_illegal_substchar );
4824
+ } else if (php_mb_is_no_encoding_unicode (MBSTRG (current_internal_encoding )-> no_encoding )) {
4825
+ if (0xd800 > MBSTRG (current_filter_illegal_substchar ) || MBSTRG (current_filter_illegal_substchar ) > 0xdfff ) {
4826
+ cp = MBSTRG (current_filter_illegal_substchar );
4827
+ } else {
4828
+ cp = 0x3f ;
4829
+ }
4824
4830
} else {
4825
4831
cp = 0x3f ;
4826
4832
}
4833
+ }
4827
4834
4828
- } else if (php_mb_is_no_encoding_utf8 (no_enc )) {
4835
+ if (cp < 0x80 ) {
4836
+ ret_len = 1 ;
4837
+ ret = (char * ) safe_emalloc (ret_len , 1 , 1 );
4838
+ ret [0 ] = cp ;
4839
+ ret [1 ] = 0 ;
4840
+ } else if (cp < 0x800 ) {
4841
+ ret_len = 2 ;
4842
+ ret = (char * ) safe_emalloc (ret_len , 1 , 1 );
4843
+ ret [0 ] = 0xc0 | (cp >> 6 );
4844
+ ret [1 ] = 0x80 | (cp & 0x3f );
4845
+ ret [2 ] = 0 ;
4846
+ } else if (cp < 0x10000 ) {
4847
+ ret_len = 3 ;
4848
+ ret = (char * ) safe_emalloc (ret_len , 1 , 1 );
4849
+ ret [0 ] = 0xe0 | (cp >> 12 );
4850
+ ret [1 ] = 0x80 | ((cp >> 6 ) & 0x3f );
4851
+ ret [2 ] = 0x80 | (cp & 0x3f );
4852
+ ret [3 ] = 0 ;
4853
+ } else {
4854
+ ret_len = 4 ;
4855
+ ret = (char * ) safe_emalloc (ret_len , 1 , 1 );
4856
+ ret [0 ] = 0xf0 | (cp >> 18 );
4857
+ ret [1 ] = 0x80 | ((cp >> 12 ) & 0x3f );
4858
+ ret [2 ] = 0x80 | ((cp >> 6 ) & 0x3f );
4859
+ ret [3 ] = 0x80 | (cp & 0x3f );
4860
+ ret [4 ] = 0 ;
4861
+ }
4829
4862
4830
- if (cp > 0xd7ff && 0xe000 > cp ) {
4831
- if (php_mb_is_no_encoding_unicode (MBSTRG (current_internal_encoding )-> no_encoding )) {
4832
- if (0xd800 > MBSTRG (current_filter_illegal_substchar ) || MBSTRG (current_filter_illegal_substchar ) > 0xdfff ) {
4833
- cp = MBSTRG (current_filter_illegal_substchar );
4834
- } else {
4835
- cp = 0x3f ;
4836
- }
4837
- } else {
4838
- cp = 0x3f ;
4839
- }
4863
+ if (output_len ) {
4864
+ * output_len = ret_len ;
4865
+ }
4866
+
4867
+ return ret ;
4868
+
4869
+ } else if (php_mb_is_no_encoding_unicode (no_enc )) {
4870
+
4871
+ if (0 > cp || 0x10ffff < cp ) {
4872
+
4873
+ if (php_mb_is_no_encoding_unicode (MBSTRG (current_internal_encoding )-> no_encoding )) {
4874
+ cp = MBSTRG (current_filter_illegal_substchar );
4875
+ } else {
4876
+ cp = 0x3f ;
4840
4877
}
4841
4878
4842
4879
}
0 commit comments