From bf0d383aba1e2353e4e8029d8efabff570f3ff1f Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 5 Feb 2014 19:16:14 +0100 Subject: [PATCH 1/6] fix tests for ICU >= 52.1 --- .../calendar_getDayOfWeekType_basic.phpt | 6 +- .../calendar_getDayOfWeekType_basic2.phpt | 34 +++++ .../dateformat_create_cal_arg_variant2.phpt | 2 +- .../dateformat_create_cal_arg_variant3.phpt | 53 +++++++ ...format_formatObject_calendar_variant2.phpt | 2 +- ...format_formatObject_calendar_variant3.phpt | 40 ++++++ ...format_formatObject_datetime_variant2.phpt | 2 +- ...format_formatObject_datetime_variant3.phpt | 33 +++++ .../dateformat_get_set_calendar_variant2.phpt | 2 +- .../dateformat_get_set_calendar_variant3.phpt | 55 ++++++++ .../dateformat_get_set_timezone_variant2.phpt | 2 +- .../dateformat_get_set_timezone_variant3.phpt | 62 +++++++++ .../dateformat_timezone_arg_variations2.phpt | 2 +- .../dateformat_timezone_arg_variations3.phpt | 45 ++++++ ext/intl/tests/formatter_format2.phpt | 2 +- ext/intl/tests/formatter_format3.phpt | 130 ++++++++++++++++++ 16 files changed, 462 insertions(+), 10 deletions(-) create mode 100644 ext/intl/tests/calendar_getDayOfWeekType_basic2.phpt create mode 100644 ext/intl/tests/dateformat_create_cal_arg_variant3.phpt create mode 100644 ext/intl/tests/dateformat_formatObject_calendar_variant3.phpt create mode 100644 ext/intl/tests/dateformat_formatObject_datetime_variant3.phpt create mode 100644 ext/intl/tests/dateformat_get_set_calendar_variant3.phpt create mode 100644 ext/intl/tests/dateformat_get_set_timezone_variant3.phpt create mode 100644 ext/intl/tests/dateformat_timezone_arg_variations3.phpt create mode 100644 ext/intl/tests/formatter_format3.phpt diff --git a/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt b/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt index d5319f1471f98..324e229de5c4d 100644 --- a/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt +++ b/ext/intl/tests/calendar_getDayOfWeekType_basic.phpt @@ -6,8 +6,8 @@ date.timezone=Atlantic/Azores = 0) + die('skip for ICU >= 4.4 and ICU < 52.1'); --FILE-- = 52.1'); +--FILE-- +setTime(strtotime('2012-02-29 00:00:00 +0000') * 1000); +var_dump( + intlcal_get_day_of_week_type($intlcal, IntlCalendar::DOW_SUNDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_MONDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_TUESDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_FRIDAY), + $intlcal->getDayOfWeekType(IntlCalendar::DOW_SATURDAY) +); + +?> +==DONE== +--EXPECT-- +int(1) +int(0) +int(0) +int(0) +int(1) +==DONE== diff --git a/ext/intl/tests/dateformat_create_cal_arg_variant2.phpt b/ext/intl/tests/dateformat_create_cal_arg_variant2.phpt index 70b862017bbbf..77ec53047bb25 100644 --- a/ext/intl/tests/dateformat_create_cal_arg_variant2.phpt +++ b/ext/intl/tests/dateformat_create_cal_arg_variant2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter: several forms of the calendar arg --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- +format($ts), "\n"; + +$cal = IntlCalendar::createInstance('UTC', 'en@calendar=islamic'); +$df = new IntlDateFormatter('es_ES', 0, 0, NULL, $cal); +echo $df->format($ts), "\n"; + +//override calendar's timezone +$cal = new IntlGregorianCalendar('UTC', NULL); +$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Madrid', $cal); +echo $df->format($ts), "\n"; + +//default calendar is gregorian +$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0); +echo $df->format($ts), "\n"; + +//try now with traditional +$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, NULL, IntlDateFormatter::TRADITIONAL); +echo $df->format($ts), "\n"; + +//the timezone can be overridden when not specifying a calendar +$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, 'UTC', IntlDateFormatter::TRADITIONAL); +echo $df->format($ts), "\n"; + +$df = new IntlDateFormatter('es_ES', 0, 0, 'UTC', 0); +echo $df->format($ts), "\n"; + +?> +==DONE== +--EXPECTF-- +domingo%S 1 de enero de 2012, 0:00:00 (GMT) +domingo%S 8 de Safar de 1433, 0:00:00 (GMT) +domingo%S 1 de enero de 2012, 1:00:00 (Hora estándar de Europa central) +sábado%S 31 de diciembre de 2011 d. C., 23:00:00 (Hora estándar %Sde las Azores) +sábado%S 7 de Safar de 1433 AH, 23:00:00 (Hora estándar %Sde las Azores) +domingo%S 8 de Safar de 1433 AH, 0:00:00 (GMT) +domingo%S 1 de enero de 2012, 0:00:00 (GMT) +==DONE== diff --git a/ext/intl/tests/dateformat_formatObject_calendar_variant2.phpt b/ext/intl/tests/dateformat_formatObject_calendar_variant2.phpt index 1ec1fa669a1a0..d59c635a7dff1 100644 --- a/ext/intl/tests/dateformat_formatObject_calendar_variant2.phpt +++ b/ext/intl/tests/dateformat_formatObject_calendar_variant2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter::formatObject(): IntlCalendar tests --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- +setTime(strtotime('2012-01-01 00:00:00')*1000.); +echo IntlDateFormatter::formatObject($cal), "\n"; +echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL, "en-US"), "\n"; + +?> +==DONE== + +--EXPECTF-- +01/01/2012, 00:00:00 +domingo, 1 de Janeiro de 2012 às 00:00:00 Hora Padrão %Sda Europa Ocidental +Jan 1, 2012, 12:00:00 AM +1/1/12, 12:00:00 AM Western European Standard %STime +Sun 2012-01-1 00,00,00.000 Portugal Time +domingo, 1 de Janeiro de 2012 às 05:00:00 GMT+03:00 +06/02/1433, 00:00:00 +Sunday, Safar 6, 1433 at 12:00:00 AM Western European Standard Time +==DONE== diff --git a/ext/intl/tests/dateformat_formatObject_datetime_variant2.phpt b/ext/intl/tests/dateformat_formatObject_datetime_variant2.phpt index 2ca9ffd7e8e41..b4e59f5b7ee04 100644 --- a/ext/intl/tests/dateformat_formatObject_datetime_variant2.phpt +++ b/ext/intl/tests/dateformat_formatObject_datetime_variant2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter::formatObject(): DateTime tests --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- + +==DONE== + +--EXPECTF-- +01/01/2012, 00:00:00 +domingo, 1 de Janeiro de 2012 às 00:00:00 Hora Padrão %Sda Europa Ocidental +Jan 1, 2012, 12:00:00 AM +1/1/12, 12:00:00 AM Western European Standard %STime +Sun 2012-01-1 00,00,00.000 Portugal Time +domingo, 1 de Janeiro de 2012 às 05:00:00 GMT+03:00 +==DONE== diff --git a/ext/intl/tests/dateformat_get_set_calendar_variant2.phpt b/ext/intl/tests/dateformat_get_set_calendar_variant2.phpt index 1c5169e65dddd..9e8d76c1bb7cb 100644 --- a/ext/intl/tests/dateformat_get_set_calendar_variant2.phpt +++ b/ext/intl/tests/dateformat_get_set_calendar_variant2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter: setCalendar()/getCalendar()/getCalendarObject() --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- +format($ts), "\n"; +var_dump($df->getCalendar(), +$df->getCalendarObject()->getType(), +$df->getCalendarObject()->getTimeZone()->getId()); +echo "\n"; +} + +$df = new IntlDateFormatter('fr@calendar=islamic', 0, 0, 'Europe/Minsk'); +d($df); + + +//changing the calendar with a cal type should not change tz +$df->setCalendar(IntlDateFormatter::TRADITIONAL); +d($df); + +//but changing with an actual calendar should +$cal = IntlCalendar::createInstance("UTC"); +$df->setCalendar($cal); +d($df); + +?> +==DONE== +--EXPECT-- +dimanche 1 janvier 2012 ap. J.-C. à 03:00:00 UTC+03:00 +int(1) +string(9) "gregorian" +string(12) "Europe/Minsk" + +dimanche 8 safar 1433 AH à 03:00:00 UTC+03:00 +int(0) +string(7) "islamic" +string(12) "Europe/Minsk" + +dimanche 1 janvier 2012 ap. J.-C. à 00:00:00 UTC +bool(false) +string(9) "gregorian" +string(3) "UTC" + +==DONE== diff --git a/ext/intl/tests/dateformat_get_set_timezone_variant2.phpt b/ext/intl/tests/dateformat_get_set_timezone_variant2.phpt index af9ddf29a46f6..f19f0ffd5bc78 100644 --- a/ext/intl/tests/dateformat_get_set_timezone_variant2.phpt +++ b/ext/intl/tests/dateformat_get_set_timezone_variant2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter: get/setTimeZone() --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- +format($ts), "\n"; +var_dump( +$df->getTimeZoneID(), +$df->getTimeZone()->getID()); +echo "\n"; +} + +$df = new IntlDateFormatter('pt_PT', 0, 0, 'Europe/Minsk'); +d($df); + +$df->setTimeZone(NULL); +d($df); + +$df->setTimeZone('Europe/Madrid'); +d($df); + +$df->setTimeZone(IntlTimeZone::createTimeZone('Europe/Paris')); +d($df); + +$df->setTimeZone(new DateTimeZone('Europe/Amsterdam')); +d($df); + +?> +==DONE== +--EXPECTF-- +domingo, 1 de Janeiro de 2012 às 03:00:00 GMT+03:00 +string(12) "Europe/Minsk" +string(12) "Europe/Minsk" + +sábado, 31 de Dezembro de 2011 às 23:00:00 Hor%s Padrão %Sdos Açores +string(15) "Atlantic/Azores" +string(15) "Atlantic/Azores" + +domingo, 1 de Janeiro de 2012 às 01:00:00 Hor%s Padrão %Sda Europa Central +string(13) "Europe/Madrid" +string(13) "Europe/Madrid" + +domingo, 1 de Janeiro de 2012 às 01:00:00 Hor%s Padrão %Sda Europa Central +string(12) "Europe/Paris" +string(12) "Europe/Paris" + +domingo, 1 de Janeiro de 2012 às 01:00:00 Hor%s Padrão %Sda Europa Central +string(16) "Europe/Amsterdam" +string(16) "Europe/Amsterdam" + +==DONE== diff --git a/ext/intl/tests/dateformat_timezone_arg_variations2.phpt b/ext/intl/tests/dateformat_timezone_arg_variations2.phpt index a957963a440e6..53ee820540336 100644 --- a/ext/intl/tests/dateformat_timezone_arg_variations2.phpt +++ b/ext/intl/tests/dateformat_timezone_arg_variations2.phpt @@ -3,7 +3,7 @@ IntlDateFormatter: several forms of the timezone arg --SKIPIF-- -= 51.2'); ?> += 0) die('skip for ICU >= 51.2 and < 52.1'); ?> --FILE-- += 52.1'); ?> +--FILE-- +format($ts), "\n"; + +$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam'); +echo $df->format($ts), "\n"; + +$df = new IntlDateFormatter('es_ES', 0, 0, new DateTimeZone('Europe/Lisbon')); +echo $df->format($ts), "\n"; + +$df = new IntlDateFormatter('es_ES', 0, 0, IntlTimeZone::createTimeZone('America/New_York')); +echo $df->format($ts), "\n"; + +//time zone has priority +$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam', new IntlGregorianCalendar('Europe/Lisbon')); +echo $df->format($ts), "\n"; + +//calendar has priority +$df = new IntlDateFormatter('es_ES', 0, 0, NULL, new IntlGregorianCalendar('Europe/Lisbon')); +echo $df->format($ts), "\n"; + +$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam', 0); +echo $df->format($ts), "\n"; + +--EXPECTF-- +sábado%S 31 de diciembre de 2011, 23:00:00 (Hora estándar de las Azores) +domingo%S 1 de enero de 2012, 1:00:00 (Hora estándar de Europa central) +domingo%S 1 de enero de 2012, 0:00:00 (Hora%S estándar de Europa occidental) +sábado%S 31 de diciembre de 2011, 19:00:00 (Hora estándar oriental) +domingo%S 1 de enero de 2012, 1:00:00 (Hora estándar de Europa central) +domingo%S 1 de enero de 2012, 0:00:00 (Hora%S estándar de Europa occidental) +domingo%S 1 de enero de 2012, 1:00:00 (Hora estándar de Europa central) diff --git a/ext/intl/tests/formatter_format2.phpt b/ext/intl/tests/formatter_format2.phpt index 0732e419dd12c..32c42f69da636 100644 --- a/ext/intl/tests/formatter_format2.phpt +++ b/ext/intl/tests/formatter_format2.phpt @@ -2,7 +2,7 @@ numfmt_format() icu >= 4.8 --SKIPIF-- - += 0) print 'skip'; ?> --FILE-- = 52.1 +--SKIPIF-- + + +--FILE-- + '##.#####################', + NumberFormatter::DECIMAL => '', + NumberFormatter::CURRENCY => '', + NumberFormatter::PERCENT => '', + NumberFormatter::SCIENTIFIC => '', + NumberFormatter::SPELLOUT => '@@@@@@@', + NumberFormatter::ORDINAL => '', + NumberFormatter::DURATION => '', + NumberFormatter::PATTERN_RULEBASED => '#####.###', + 1234999, // bad one + ); + + $integer = array( + NumberFormatter::ORDINAL => '', + NumberFormatter::DURATION => '', + ); + $locales = array( + 'en_US', + 'ru_UA', + 'de', + 'fr', + 'en_UK' + ); + + $str_res = ''; + $number = 1234567.891234567890000; + + foreach( $locales as $locale ) + { + $str_res .= "\nLocale is: $locale\n"; + foreach( $styles as $style => $pattern ) + { + $fmt = ut_nfmt_create( $locale, $style, $pattern ); + + if(!$fmt) { + $str_res .= "Bad formatter!\n"; + continue; + } + $str_res .= dump( isset($integer[$style])?ut_nfmt_format( $fmt, $number, NumberFormatter::TYPE_INT32):ut_nfmt_format( $fmt, $number ) ) . "\n"; + } + } + return $str_res; +} + +include_once( 'ut_common.inc' ); + +// Run the test +ut_run(); + +?> +--EXPECTREGEX-- +Locale is: en_US +'1234567.89123457' +'1,234,567.891' +'\$1,234,567.89' +'123,456,789%' +'1.23456789123457E6' +'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five seven' +'1,234,567(th|ᵗʰ)' +'342:56:07' +'#####.###' +Bad formatter! + +Locale is: ru_UA +'1234567,89123457' +'1 234 567,891' +'1 234 567,89 ?(грн\.|₴)' +'123 456 789 ?%' +'1,23456789123457E6' +'один миллион двести тридцать четыре тысяч пятьсот шестьдесят семь запятая восемь девять один два три четыре пять семь' +'1 234 567.?' +'1 234 567' +'#####.###' +Bad formatter! + +Locale is: de +'1234567,89123457' +'1.234.567,891' +'(¤ )?1.234.567,89( ¤)?' +'123\.456\.789 %' +'1,23456789123457E6' +'eine Million zwei­hundert­vier­und­dreißig­tausend­fünf­hundert­sieben­und­sechzig Komma acht neun eins zwei drei vier fünf sieben' +'1.234.567.?' +'1.234.567' +'#####.###' +Bad formatter! + +Locale is: fr +'1234567,89123457' +'1 234 567,891' +'1 234 567,89 ¤' +'123 456 789 ?%' +'1,23456789123457E6' +'un million deux cent trente-quatre mille cinq cent soixante-sept virgule huit neuf un deux trois quatre cinq sept' +'1 234 567e' +'1 234 567' +'#####.###' +Bad formatter! + +Locale is: en_UK +'1234567.89123457' +'1,234,567.891' +'¤1,234,567.89' +'123,456,789%' +'1.23456789123457E6' +'one million,? two hundred (and )?thirty-four thousand,? five hundred (and )?sixty-seven point eight nine one two three four five seven' +'1,234,567(th|ᵗʰ)' +'342:56:07' +'#####.###' +Bad formatter! From 913dde8ec1df241a2536b027cfc863fc22c29689 Mon Sep 17 00:00:00 2001 From: Danack Date: Thu, 13 Feb 2014 14:48:51 +0000 Subject: [PATCH 2/6] Allow valid multi-byte utf-8 characters to be allowed as file names in phar archives. --- ext/phar/phar_path_check.c | 182 ++++++++++++++++++-------- ext/phar/phar_path_check.re | 24 ++++ ext/phar/tests/create_path_error.phpt | 31 ++++- 3 files changed, 177 insertions(+), 60 deletions(-) diff --git a/ext/phar/phar_path_check.c b/ext/phar/phar_path_check.c index db97efcbe3090..959c9b6e0a014 100644 --- a/ext/phar/phar_path_check.c +++ b/ext/phar/phar_path_check.c @@ -4,7 +4,7 @@ +----------------------------------------------------------------------+ | phar php single-file executable PHP extension | +----------------------------------------------------------------------+ - | Copyright (c) 2007-2014 The PHP Group | + | Copyright (c) 2007-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -46,60 +46,69 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) #line 47 "ext/phar/phar_path_check.c" { YYCTYPE yych; + unsigned int yyaccept = 0; if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; - if (yych <= '.') { - if (yych <= '\n') { - if (yych <= 0x00) goto yy13; - if (yych <= '\t') goto yy10; - goto yy12; + if (yych <= '>') { + if (yych <= 0x19) { + if (yych <= 0x00) goto yy16; + if (yych == '\n') goto yy15; + goto yy14; } else { - if (yych <= 0x19) goto yy10; - if (yych == '*') goto yy6; - goto yy15; + if (yych <= '*') { + if (yych <= ')') goto yy18; + goto yy6; + } else { + if (yych != '/') goto yy18; + } } } else { - if (yych <= '?') { - if (yych <= '/') goto yy2; - if (yych <= '>') goto yy15; - goto yy8; - } else { + if (yych <= 0x7F) { + if (yych <= '?') goto yy8; if (yych == '\\') goto yy4; - if (yych <= 0x7F) goto yy15; - goto yy10; + goto yy18; + } else { + if (yych <= 0xDF) { + if (yych <= 0xBF) goto yy14; + goto yy10; + } else { + if (yych <= 0xEF) goto yy12; + if (yych <= 0xF7) goto yy13; + goto yy14; + } } } -yy2: + yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if (yych <= '-') goto yy3; - if (yych <= '.') goto yy16; - if (yych <= '/') goto yy18; + if (yych <= '.') goto yy29; + if (yych <= '/') goto yy30; yy3: -#line 93 "ext/phar/phar_path_check.re" +#line 117 "ext/phar/phar_path_check.re" { goto loop; } -#line 84 "ext/phar/phar_path_check.c" +#line 93 "ext/phar/phar_path_check.c" yy4: ++YYCURSOR; -#line 60 "ext/phar/phar_path_check.re" +#line 63 "ext/phar/phar_path_check.re" { *error = "back-slash"; return pcr_err_back_slash; } -#line 92 "ext/phar/phar_path_check.c" +#line 101 "ext/phar/phar_path_check.c" yy6: ++YYCURSOR; -#line 64 "ext/phar/phar_path_check.re" +#line 67 "ext/phar/phar_path_check.re" { *error = "star"; return pcr_err_star; } -#line 100 "ext/phar/phar_path_check.c" +#line 109 "ext/phar/phar_path_check.c" yy8: ++YYCURSOR; -#line 68 "ext/phar/phar_path_check.re" +#line 71 "ext/phar/phar_path_check.re" { if (**s == '/') { (*s)++; @@ -108,22 +117,39 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) *error = NULL; return pcr_use_query; } -#line 112 "ext/phar/phar_path_check.c" +#line 121 "ext/phar/phar_path_check.c" yy10: ++YYCURSOR; + if ((yych = *YYCURSOR) <= 0x7F) goto yy11; + if (yych <= 0xBF) goto yy27; yy11: -#line 76 "ext/phar/phar_path_check.re" +#line 100 "ext/phar/phar_path_check.re" { *error ="illegal character"; return pcr_err_illegal_char; } -#line 121 "ext/phar/phar_path_check.c" +#line 132 "ext/phar/phar_path_check.c" yy12: - yych = *++YYCURSOR; + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 0x7F) goto yy11; + if (yych <= 0xBF) goto yy24; goto yy11; yy13: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 0x7F) goto yy11; + if (yych <= 0xBF) goto yy19; + goto yy11; +yy14: + yych = *++YYCURSOR; + goto yy11; +yy15: + yych = *++YYCURSOR; + goto yy11; +yy16: ++YYCURSOR; -#line 80 "ext/phar/phar_path_check.re" +#line 104 "ext/phar/phar_path_check.re" { if (**s == '/') { (*s)++; @@ -137,49 +163,97 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) *error = NULL; return pcr_is_ok; } -#line 141 "ext/phar/phar_path_check.c" -yy15: +#line 167 "ext/phar/phar_path_check.c" +yy18: yych = *++YYCURSOR; goto yy3; -yy16: +yy19: yych = *++YYCURSOR; - if (yych <= 0x00) goto yy21; - if (yych <= '-') goto yy17; - if (yych <= '.') goto yy20; - if (yych <= '/') goto yy21; -yy17: + if (yych <= 0x7F) goto yy20; + if (yych <= 0xBF) goto yy21; +yy20: YYCURSOR = YYMARKER; - goto yy3; -yy18: + if (yyaccept <= 0) { + goto yy3; + } else { + goto yy11; + } +yy21: + yych = *++YYCURSOR; + if (yych <= 0x7F) goto yy20; + if (yych >= 0xC0) goto yy20; ++YYCURSOR; -#line 48 "ext/phar/phar_path_check.re" +#line 91 "ext/phar/phar_path_check.re" + { + (*s)++; + (*len)--; + (*s)++; + (*len)--; + (*s)++; + (*len)--; + goto loop; + } +#line 197 "ext/phar/phar_path_check.c" +yy24: + yych = *++YYCURSOR; + if (yych <= 0x7F) goto yy20; + if (yych >= 0xC0) goto yy20; + ++YYCURSOR; +#line 84 "ext/phar/phar_path_check.re" + { + (*s)++; + (*len)--; + (*s)++; + (*len)--; + goto loop; + } +#line 211 "ext/phar/phar_path_check.c" +yy27: + ++YYCURSOR; +#line 79 "ext/phar/phar_path_check.re" + { + (*s)++; + (*len)--; + goto loop; + } +#line 220 "ext/phar/phar_path_check.c" +yy29: + yych = *++YYCURSOR; + if (yych <= 0x00) goto yy33; + if (yych <= '-') goto yy20; + if (yych <= '.') goto yy32; + if (yych <= '/') goto yy33; + goto yy20; +yy30: + ++YYCURSOR; +#line 51 "ext/phar/phar_path_check.re" { *error = "double slash"; return pcr_err_double_slash; } -#line 161 "ext/phar/phar_path_check.c" -yy20: +#line 235 "ext/phar/phar_path_check.c" +yy32: yych = *++YYCURSOR; - if (yych <= 0x00) goto yy23; - if (yych == '/') goto yy23; - goto yy17; -yy21: + if (yych <= 0x00) goto yy35; + if (yych == '/') goto yy35; + goto yy20; +yy33: ++YYCURSOR; -#line 56 "ext/phar/phar_path_check.re" +#line 59 "ext/phar/phar_path_check.re" { *error = "current directory reference"; return pcr_err_curr_dir; } -#line 174 "ext/phar/phar_path_check.c" -yy23: +#line 248 "ext/phar/phar_path_check.c" +yy35: ++YYCURSOR; -#line 52 "ext/phar/phar_path_check.re" +#line 55 "ext/phar/phar_path_check.re" { *error = "upper directory reference"; return pcr_err_up_dir; } -#line 182 "ext/phar/phar_path_check.c" +#line 256 "ext/phar/phar_path_check.c" } -#line 96 "ext/phar/phar_path_check.re" +#line 120 "ext/phar/phar_path_check.re" } diff --git a/ext/phar/phar_path_check.re b/ext/phar/phar_path_check.re index e43b3f846e5ec..32cde2711c566 100644 --- a/ext/phar/phar_path_check.re +++ b/ext/phar/phar_path_check.re @@ -42,6 +42,9 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) loop: /*!re2c END = "\x00"; +MB2 = ([\xC0-\xDF][\x80-\xBF]); +MB3 = ([\xE0-\xEF][\x80-\xBF]{2}); +MB4 = ([\xF0-\xF7][\x80-\xBF]{3}); ILL = [\x01-\x19\x80-\xFF]; EOS = "/" | END; ANY = .; @@ -73,6 +76,27 @@ ANY = .; *error = NULL; return pcr_use_query; } +MB2 { + (*s)++; + (*len)--; + goto loop; + } +MB3 { + (*s)++; + (*len)--; + (*s)++; + (*len)--; + goto loop; + } +MB4 { + (*s)++; + (*len)--; + (*s)++; + (*len)--; + (*s)++; + (*len)--; + goto loop; + } ILL { *error ="illegal character"; return pcr_err_illegal_char; diff --git a/ext/phar/tests/create_path_error.phpt b/ext/phar/tests/create_path_error.phpt index d3fc03586065f..7451d9cd3985e 100644 --- a/ext/phar/tests/create_path_error.phpt +++ b/ext/phar/tests/create_path_error.phpt @@ -22,15 +22,26 @@ var_dump(file_get_contents($pname . '/b.php')); function error_handler($errno, $errmsg) { - echo "Error: $errmsg\n"; + echo "Error: $errmsg"; } set_error_handler('error_handler'); -$checks = array('/', '.', '../', 'a/..', 'a/', 'b//a.php'); +$count = 0; +$checks = array( + '/', '.', '../', 'a/..', 'a/', 'b//a.php', + "Font\xE5\x84\xB7\xE9\xBB\x91pro.ttf", //two valid multi-byte characters + "\xF0\x9F\x98\x8D.ttf", // valid 4 byte char - smiling face with heart-shaped eyes + "Font\xE9\xBBpro.ttf", //Invalid multi-byte character - missing last byte + "Font\xBB\x91pro.ttf", //Invalid multi-byte character - missing first byte + "\xFC\x81\x81\x81\x81pro.ttf", //RFC 3629 limited char points to 0000-10FFFF aka 5 byte utf-8 not valid +); foreach($checks as $check) { + $count++; + echo "$count:"; file_put_contents($pname . '/' . $check, "error"); + echo "\n"; } $phar = new Phar($fname); @@ -54,9 +65,17 @@ foreach($checks as $check) --EXPECTF-- string(5) "query" string(5) "query" -Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty -Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty -Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty -Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty +1:Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty +2:Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty +3:Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty +4:Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty +5: +6: +7: +8: +9:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character +10:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character +11:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character ===DONE=== + From d7c6bb8a86d10d45ff24cff78fdc0029589e19cc Mon Sep 17 00:00:00 2001 From: Danack Date: Thu, 13 Feb 2014 15:04:04 +0000 Subject: [PATCH 3/6] Fixed misunderstanding of re2c. --- ext/phar/phar_path_check.c | 36 ++++++++++++------------------------ ext/phar/phar_path_check.re | 12 ------------ 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/ext/phar/phar_path_check.c b/ext/phar/phar_path_check.c index 959c9b6e0a014..7b1ff695ba008 100644 --- a/ext/phar/phar_path_check.c +++ b/ext/phar/phar_path_check.c @@ -85,7 +85,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) if (yych <= '.') goto yy29; if (yych <= '/') goto yy30; yy3: -#line 117 "ext/phar/phar_path_check.re" +#line 105 "ext/phar/phar_path_check.re" { goto loop; } @@ -123,7 +123,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) if ((yych = *YYCURSOR) <= 0x7F) goto yy11; if (yych <= 0xBF) goto yy27; yy11: -#line 100 "ext/phar/phar_path_check.re" +#line 88 "ext/phar/phar_path_check.re" { *error ="illegal character"; return pcr_err_illegal_char; @@ -149,7 +149,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) goto yy11; yy16: ++YYCURSOR; -#line 104 "ext/phar/phar_path_check.re" +#line 92 "ext/phar/phar_path_check.re" { if (**s == '/') { (*s)++; @@ -183,40 +183,28 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) if (yych <= 0x7F) goto yy20; if (yych >= 0xC0) goto yy20; ++YYCURSOR; -#line 91 "ext/phar/phar_path_check.re" +#line 85 "ext/phar/phar_path_check.re" { - (*s)++; - (*len)--; - (*s)++; - (*len)--; - (*s)++; - (*len)--; goto loop; } -#line 197 "ext/phar/phar_path_check.c" +#line 191 "ext/phar/phar_path_check.c" yy24: yych = *++YYCURSOR; if (yych <= 0x7F) goto yy20; if (yych >= 0xC0) goto yy20; ++YYCURSOR; -#line 84 "ext/phar/phar_path_check.re" +#line 82 "ext/phar/phar_path_check.re" { - (*s)++; - (*len)--; - (*s)++; - (*len)--; goto loop; } -#line 211 "ext/phar/phar_path_check.c" +#line 201 "ext/phar/phar_path_check.c" yy27: ++YYCURSOR; #line 79 "ext/phar/phar_path_check.re" { - (*s)++; - (*len)--; goto loop; } -#line 220 "ext/phar/phar_path_check.c" +#line 208 "ext/phar/phar_path_check.c" yy29: yych = *++YYCURSOR; if (yych <= 0x00) goto yy33; @@ -231,7 +219,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) *error = "double slash"; return pcr_err_double_slash; } -#line 235 "ext/phar/phar_path_check.c" +#line 223 "ext/phar/phar_path_check.c" yy32: yych = *++YYCURSOR; if (yych <= 0x00) goto yy35; @@ -244,7 +232,7 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) *error = "current directory reference"; return pcr_err_curr_dir; } -#line 248 "ext/phar/phar_path_check.c" +#line 236 "ext/phar/phar_path_check.c" yy35: ++YYCURSOR; #line 55 "ext/phar/phar_path_check.re" @@ -252,8 +240,8 @@ phar_path_check_result phar_path_check(char **s, int *len, const char **error) *error = "upper directory reference"; return pcr_err_up_dir; } -#line 256 "ext/phar/phar_path_check.c" +#line 244 "ext/phar/phar_path_check.c" } -#line 120 "ext/phar/phar_path_check.re" +#line 108 "ext/phar/phar_path_check.re" } diff --git a/ext/phar/phar_path_check.re b/ext/phar/phar_path_check.re index 32cde2711c566..c86a90c66b5ad 100644 --- a/ext/phar/phar_path_check.re +++ b/ext/phar/phar_path_check.re @@ -77,24 +77,12 @@ ANY = .; return pcr_use_query; } MB2 { - (*s)++; - (*len)--; goto loop; } MB3 { - (*s)++; - (*len)--; - (*s)++; - (*len)--; goto loop; } MB4 { - (*s)++; - (*len)--; - (*s)++; - (*len)--; - (*s)++; - (*len)--; goto loop; } ILL { From 0acdfb7932dcf7b8abc566038ecf7f6243aafe44 Mon Sep 17 00:00:00 2001 From: Danack Date: Thu, 13 Feb 2014 18:20:49 +0000 Subject: [PATCH 4/6] Added test for writing to phar:// --- ext/phar/tests/create_new_phar.phpt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/phar/tests/create_new_phar.phpt b/ext/phar/tests/create_new_phar.phpt index ec57c272173f2..26794095e15f9 100644 --- a/ext/phar/tests/create_new_phar.phpt +++ b/ext/phar/tests/create_new_phar.phpt @@ -9,8 +9,13 @@ phar.require_hash=1 ===DONE=== @@ -18,4 +23,5 @@ include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.pha --EXPECT-- brand new! +Text in utf8 file. ===DONE=== From ac81e126271c0c2fbd843856962e50430e169bd7 Mon Sep 17 00:00:00 2001 From: Danack Date: Fri, 14 Feb 2014 15:45:19 +0000 Subject: [PATCH 5/6] Changed year. --- ext/phar/phar_path_check.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/phar/phar_path_check.re b/ext/phar/phar_path_check.re index c86a90c66b5ad..b182d784800ab 100644 --- a/ext/phar/phar_path_check.re +++ b/ext/phar/phar_path_check.re @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | phar php single-file executable PHP extension | +----------------------------------------------------------------------+ - | Copyright (c) 2007-2013 The PHP Group | + | Copyright (c) 2007-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | From 6d4a6957a6a2b80b98acad791d81af3071f53910 Mon Sep 17 00:00:00 2001 From: Danack Date: Fri, 14 Feb 2014 17:16:18 +0000 Subject: [PATCH 6/6] Committed generated C file with updated year. --- ext/phar/phar_path_check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/phar/phar_path_check.c b/ext/phar/phar_path_check.c index 7b1ff695ba008..11d126e5351e6 100644 --- a/ext/phar/phar_path_check.c +++ b/ext/phar/phar_path_check.c @@ -4,7 +4,7 @@ +----------------------------------------------------------------------+ | phar php single-file executable PHP extension | +----------------------------------------------------------------------+ - | Copyright (c) 2007-2013 The PHP Group | + | Copyright (c) 2007-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is |