From a2a307759dd54d69130184f85b7a9c1c96793b28 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 29 Jul 2015 14:11:13 +0200 Subject: whitelist content:attr(placeholder), universally supported --- itjs.php | 1 + 1 file changed, 1 insertion(+) diff --git a/itjs.php b/itjs.php index 88fe03f..332e0dc 100644 --- a/itjs.php +++ b/itjs.php @@ -60,6 +60,7 @@ else if (it::match('\.css', $file)) ':valid:' => ":", # hack for iOS datetime '([^/])\*(\w)' => '$1$2', 'svg\..*' => "", # ignore svg styles + '\battr\(.*?\)' => "'x'", # ignore content:attr(placeholder) ), $data ); -- cgit v1.2.3 From d2373fd5ce8472833bab1f0c7f8b532131582466 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 5 Aug 2015 14:20:40 +0200 Subject: make it::fatal exits more discernable --- it.class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it.class b/it.class index 494fb1b..8faac1f 100644 --- a/it.class +++ b/it.class @@ -266,7 +266,7 @@ static function fatal($p) it::error($p); if ($_SERVER['REMOTE_ADDR']) header("HTTP/1.0 500 Internal Server Error"); - exit(1); + exit(99); } -- cgit v1.2.3 From 7357218e63e76862c2fb273f2d41ae1fcdf773bf Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 5 Aug 2015 16:15:53 +0200 Subject: more verbose err msg --- it_url.class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it_url.class b/it_url.class index c465f13..984f621 100644 --- a/it_url.class +++ b/it_url.class @@ -385,7 +385,7 @@ function request($p=array()) if (time() >= $endtime) { $result = $this->result = false; - $errstr = $this->errstr = "totaltimeout reached"; + $errstr = $this->errstr = "totaltimeout (" . $p['totaltimeout'] . ") reached"; } if ($p['maxlength'] && (strlen($this->data) + $len > $p['maxlength'])) { -- cgit v1.2.3 From 7fd4e76f58d377cf978f97200145167eeb2aab9e Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Fri, 7 Aug 2015 18:06:52 +0200 Subject: correctly determine and restore locale in csv() --- it_pipe.class | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/it_pipe.class b/it_pipe.class index 737908a..6b43466 100644 --- a/it_pipe.class +++ b/it_pipe.class @@ -168,7 +168,8 @@ function csv($forceschema = null) foreach (preg_grep('/^$/', $cols) as $idx => $dummy) $cols[$idx] = "field$idx"; # replace empty column names - $oldlocale = setlocale(LC_CTYPE, 'de_CH.iso-8859-1'); # this works for utf-8 as well + $oldlocale = setlocale(LC_CTYPE, "0"); + setlocale(LC_CTYPE, 'de_CH.iso-8859-1'); # this works for utf-8 as well foreach ($this->lines as $line) $records[] = (object)array_combine($cols, str_getcsv($line, $splitchar, '"')); # could do a function_exists('str_getcsv') here... -- cgit v1.2.3 From 534899acf620b83936a8e445c806cc481d789050 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 13:59:59 +0200 Subject: correctly handle non-utf8 in keys --- it.class | 4 ++-- tests/it.t | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/it.class b/it.class index 8faac1f..e6f8006 100644 --- a/it.class +++ b/it.class @@ -429,8 +429,8 @@ static function any2utf8($value, $errprefix = "") if (is_array($value)) { foreach ($value as $idx => $v) - if (is_string($v) || is_array($v)) - $value[$idx] = self::any2utf8($v, $errprefix); + $newarr[self::any2utf8($idx)] = is_string($v) || is_array($v) ? self::any2utf8($v, $errprefix) : $v; + $value = $newarr; } else if (is_string($value)) { diff --git a/tests/it.t b/tests/it.t index a50b4dc..57c8be1 100755 --- a/tests/it.t +++ b/tests/it.t @@ -389,6 +389,7 @@ is(it::any2utf8("a💚b"), "a💚b", "it::any2utf8 correctly handles 4-byte utf- is(it::any2utf8(array("foo", utf8_decode("bär"))), array("foo", "bär"), "any2utf8 on arrays"); is(it::any2utf8(array("foo", array(utf8_decode("bär")))), array("foo", array("bär")), "any2utf8 on recursive arrays"); is(it::any2utf8(array(1, true, false, null)), array(1, true, false, null), "any2utf8 should leave types alone"); +is(it::any2utf8(array(utf8_decode('Müller') => utf8_decode('Müller'))), array('Müller' => 'Müller'), "it::any2utf8 latin1 keys"); foreach (array($dummy, false, true, null, 1, "a", "Ä", "/", array()) as $var) is(it::json_decode(it::json_encode($var)), $var); -- cgit v1.2.3 From 6fb8dda1d303697e07e61483fbb3ca8eef038d8f Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 14:19:46 +0200 Subject: php 5.3 compatibility required now?! --- tests/it.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/it.t b/tests/it.t index 57c8be1..02f1f9a 100755 --- a/tests/it.t +++ b/tests/it.t @@ -241,7 +241,7 @@ match( 'abc', "aBc", false, "set case sensitivity by parameter", - array('casesensitive' => 1), + array('casesensitive' => 1) ); match( @@ -309,7 +309,7 @@ is(it::replace(array('a' => "b", 'b' => "c"), "a"), "c"); is(it::grep('ismatch', array('ismatch', 'isnomatch')), array('ismatch'), 'grep with simple regex'); is(it::grep('!', array('ismatch!', 'isnomatch')), array('ismatch!'), '! in regex'); -is(it::grep('lower|UPPER', array('lower', 'LOWER', 'upper', 'UPPER'), 'casesensitive' => 1), array(0 => 'lower', 3 => 'UPPER'), 'set casesensitive'); +is(it::grep('lower|UPPER', array('lower', 'LOWER', 'upper', 'UPPER'), array('casesensitive' => 1)), array(0 => 'lower', 3 => 'UPPER'), 'set casesensitive'); is(it::grep('match', array('foo' => 'match', 'bar' => 'gna')), array('foo' => 'match'), 'with keys'); setlocale(LC_CTYPE, $oldlocale); -- cgit v1.2.3 From 160f67d68300cb5bc49f305c16c0d4da5d551821 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 15:58:50 +0200 Subject: adapt tests to strict comparison --- tests/it.t | 22 +++++++++++----------- tests/it_url.t | 2 +- tests/it_url_slow.t | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/it.t b/tests/it.t index 02f1f9a..10c4d0e 100755 --- a/tests/it.t +++ b/tests/it.t @@ -58,25 +58,25 @@ match( match( '\bblah\b', 'ablahc', - false, + null, 'don\'t match \b at word chars' ); match( '\bblah\b', 'Üblahä', - false, + null, 'don\'t match \b at umlaute' ); match( '\Bblah\B', ' blah ', - false, + null, 'don\'t match \B at spaces' ); match( '\Bblah\B', 'blah', - false, + null, 'don\'t match \B at end of string' ); @@ -112,7 +112,7 @@ match( match( '\ba', 'äa', - '', + null, '\b must know umlauts' ); @@ -133,19 +133,19 @@ $escapedwordregex = preg_replace('|[\\\\/]|', '', $escapedwordregex); match( '\\\\w+', $escapedwordregex, - false, + null, 'don\'t parse \w in \\\\w at beginning (no match)' ); match( 'aaa\\\\w+', 'aaa' . $escapedwordregex, - false, + null, 'don\'t parse \w in \\\\w after chars (no match)' ); match( '\\\\\\\\w+', '\\' . $escapedwordregex, - false, + null, 'don\'t parse \w in \\\\\\\w (no match)' ); @@ -157,7 +157,7 @@ match( match( '[\w]+', '[[[]]]---', - false, + null, 'replace \w in [\w] correctly (no match)' ); @@ -169,7 +169,7 @@ match( match( '[\\\\w]+', ' blabergna ', - false, + null, 'don\'t parse \w in [\\\\w] (no match)' ); @@ -239,7 +239,7 @@ match( match( 'abc', "aBc", - false, + null, "set case sensitivity by parameter", array('casesensitive' => 1) ); diff --git a/tests/it_url.t b/tests/it_url.t index 711b5f1..c843bba 100755 --- a/tests/it_url.t +++ b/tests/it_url.t @@ -109,7 +109,7 @@ ok( ); is( $url->result, - 200, + '200', '$url->result = 200' ); is( diff --git a/tests/it_url_slow.t b/tests/it_url_slow.t index 74440ce..aa85a80 100755 --- a/tests/it_url_slow.t +++ b/tests/it_url_slow.t @@ -21,7 +21,7 @@ $res = ok( 'it_url::get() fails after timeout seconds with no output', ); $res2 = is( - floor(microtime(true) - $start), 5, + intval(microtime(true) - $start), 5, '... and fails as soon as timeout is surpassed', ); sleep(1); # wait for testserver @@ -43,7 +43,7 @@ $res = ok( 'it_url::get() fails for response slower than totaltimeout', ); $res2 = is( - floor(microtime(true) - $start), 5, + intval(microtime(true) - $start), 5, '... and fails as soon as totaltimeout is surpassed' ); sleep(1); # wait for testserver -- cgit v1.2.3 From 21205b1d20a4c0325e3b4484f1501078f6dd6846 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 16:01:12 +0200 Subject: php 5.3 compatibility --- tests/it_url.t | 28 ++++++++++++++-------------- tests/it_url_slow.t | 12 ++++++------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/it_url.t b/tests/it_url.t index c843bba..0b81881 100755 --- a/tests/it_url.t +++ b/tests/it_url.t @@ -131,7 +131,7 @@ handle_server( is( it_url::get('http://localhost:8000/'), "Testserver root output", - 'it_url::get() static call with port', + 'it_url::get() static call with port' ) ); @@ -139,7 +139,7 @@ handle_server( is( it_url::get(array('url' => 'http://localhost:8000/', 'maxlength' => 100)), "Testserver root output", - 'it_url::get() static call with port and maxlength', + 'it_url::get() static call with port and maxlength' ) ); @@ -147,7 +147,7 @@ handle_server( is( it_url::get(array('url' => 'http://localhost:8000/', 'maxlength' => 5)), false, - 'it_url::get() static call with port and too small maxlength', + 'it_url::get() static call with port and too small maxlength' ) ); @@ -155,7 +155,7 @@ handle_server( is( it_url::get('http://localhost:8000/temp_redirect'), "Testserver output after temporary redirect", - 'it_url::get() follows temproary redirect', + 'it_url::get() follows temproary redirect' ) ); @@ -163,7 +163,7 @@ handle_server( is( it_url::get('http://localhost:8000/perm_redirect'), "Testserver output after permanent redirect", - 'it_url::get() follows permanent redirect', + 'it_url::get() follows permanent redirect' ) ); @@ -171,7 +171,7 @@ handle_server( is( it_url::get('http://localhost:8000/relative_redirect'), "Testserver output after relative redirect", - 'TODO: it_url::get() follows relative redirect correctly', + 'TODO: it_url::get() follows relative redirect correctly' ) ); @@ -179,32 +179,32 @@ handle_server( is( it_url::get('http://localhost:8000/nohost_redirect'), "Testserver output after nohost redirect", - 'TODO: it_url::get() follows redirect without host correctly', + 'TODO: it_url::get() follows redirect without host correctly' ) ); $output = handle_server( ok( !it_url::get(U('http://localhost:8000/redirect_loop', 'num' => 10)), - 'it_url::get() handles redirect loop', + 'it_url::get() handles redirect loop' ) ); $last_num = it::match('num=(\d+)', end($output)); if (!ok( $last_num == 5, - 'it_url::get() aborts redirect loop after 5 redirects', + 'it_url::get() aborts redirect loop after 5 redirects' )) diag($output); $output = handle_server( ok( !it_url::get('url' => 'http://localhost:8000/does_not_exist', 'retries' => 4), - 'it_url::get() retries on empty response', + 'it_url::get() retries on empty response' ) ); if (!ok( count(preg_grep('/^Got Request:/', $output)) == 5, - 'it_url::get() respects set retry count', + 'it_url::get() respects set retry count' )) diag($output); @@ -212,7 +212,7 @@ handle_server( is( it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_HOST')), 'localhost:8000', - 'it_url::get() sets correct Host header', + 'it_url::get() sets correct Host header' ) ); @@ -220,14 +220,14 @@ handle_server( is( it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_ACCEPT_LANGUAGE')), T_lang(), - 'it_url::get() sets correct Accept-Language header', + 'it_url::get() sets correct Accept-Language header' ) ); handle_server( ok( it::match('Mozilla', it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_USER_AGENT'))), - 'it_url::get() sets User-Agent containing Mozilla', + 'it_url::get() sets User-Agent containing Mozilla' ) ); diff --git a/tests/it_url_slow.t b/tests/it_url_slow.t index aa85a80..22aae10 100755 --- a/tests/it_url_slow.t +++ b/tests/it_url_slow.t @@ -11,18 +11,18 @@ handle_server( is( it_url::get('http://localhost:8000/short_sleep'), "Testserver output after short sleep", - 'it_url::get() waits for 4 seconds', + 'it_url::get() waits for 4 seconds' ) ); $start = microtime(true); $res = ok( !it_url::get(array('url' => 'http://localhost:8000/long_sleep', 'timeout' => 5, 'retries' => 0)), - 'it_url::get() fails after timeout seconds with no output', + 'it_url::get() fails after timeout seconds with no output' ); $res2 = is( intval(microtime(true) - $start), 5, - '... and fails as soon as timeout is surpassed', + '... and fails as soon as timeout is surpassed' ); sleep(1); # wait for testserver $output = server_output(); @@ -33,14 +33,14 @@ handle_server( is( it_url::get('http://localhost:8000/slow_response'), join('', it::map('"Testserver slow output $v\n"', range(0, 5))), - 'it_url::get() waits for slow response with continuous output', + 'it_url::get() waits for slow response with continuous output' ) ); $start = microtime(true); $res = ok( !it_url::get(array('url' => 'http://localhost:8000/slow_response', 'totaltimeout' => 5, 'retries' => 0)), - 'it_url::get() fails for response slower than totaltimeout', + 'it_url::get() fails for response slower than totaltimeout' ); $res2 = is( intval(microtime(true) - $start), 5, @@ -54,7 +54,7 @@ if (!$res || !$res2) handle_server( ok( it_url::get(U('http://localhost:8000/repeat', 'string' => "abc", 'num' => 1024 * 1024)) == str_repeat("abc", 1024 * 1024), - 'it_url::get() handles large response', + 'it_url::get() handles large response' ) ); -- cgit v1.2.3 From 28ddc800b720c62fe2acc12e2bce88c0b4efaad8 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 16:04:53 +0200 Subject: php 5.3 compatibility --- tests/it_url.t | 10 +++++----- tests/it_url_slow.t | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/it_url.t b/tests/it_url.t index 0b81881..514593c 100755 --- a/tests/it_url.t +++ b/tests/it_url.t @@ -185,7 +185,7 @@ handle_server( $output = handle_server( ok( - !it_url::get(U('http://localhost:8000/redirect_loop', 'num' => 10)), + !it_url::get(U('http://localhost:8000/redirect_loop', array('num' => 10))), 'it_url::get() handles redirect loop' ) ); @@ -198,7 +198,7 @@ if (!ok( $output = handle_server( ok( - !it_url::get('url' => 'http://localhost:8000/does_not_exist', 'retries' => 4), + !it_url::get(array('url' => 'http://localhost:8000/does_not_exist', 'retries' => 4)), 'it_url::get() retries on empty response' ) ); @@ -210,7 +210,7 @@ if (!ok( handle_server( is( - it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_HOST')), + it_url::get(U('http://localhost:8000/get_server_value', array('key' => 'HTTP_HOST'))), 'localhost:8000', 'it_url::get() sets correct Host header' ) @@ -218,7 +218,7 @@ handle_server( handle_server( is( - it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_ACCEPT_LANGUAGE')), + it_url::get(U('http://localhost:8000/get_server_value', array('key' => 'HTTP_ACCEPT_LANGUAGE'))), T_lang(), 'it_url::get() sets correct Accept-Language header' ) @@ -226,7 +226,7 @@ handle_server( handle_server( ok( - it::match('Mozilla', it_url::get(U('http://localhost:8000/get_server_value', 'key' => 'HTTP_USER_AGENT'))), + it::match('Mozilla', it_url::get(U('http://localhost:8000/get_server_value', array('key' => 'HTTP_USER_AGENT')))), 'it_url::get() sets User-Agent containing Mozilla' ) ); diff --git a/tests/it_url_slow.t b/tests/it_url_slow.t index 22aae10..1dc3d78 100755 --- a/tests/it_url_slow.t +++ b/tests/it_url_slow.t @@ -53,7 +53,7 @@ if (!$res || !$res2) handle_server( ok( - it_url::get(U('http://localhost:8000/repeat', 'string' => "abc", 'num' => 1024 * 1024)) == str_repeat("abc", 1024 * 1024), + it_url::get(U('http://localhost:8000/repeat', 'string' => "abc", array('num' => 1024 * 1024))) == str_repeat("abc", 1024 * 1024), 'it_url::get() handles large response' ) ); -- cgit v1.2.3 From b26fcf8a18d32a49728516d4cdcb41c4f2ae8c93 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 16:06:24 +0200 Subject: php 5.3 compatibility --- tests/it_url.t | 2 +- tests/it_url_slow.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/it_url.t b/tests/it_url.t index 514593c..5cb2b29 100755 --- a/tests/it_url.t +++ b/tests/it_url.t @@ -231,7 +231,7 @@ handle_server( ) ); -$pages = it_url::get_multi('urls' => array('a' => 'http://www.gna.ch/', 'b' => 'http://search.ch/')); +$pages = it_url::get_multi(array('urls' => array('a' => 'http://www.gna.ch/', 'b' => 'http://search.ch/'))); ok(strpos($pages['a'], ''), 'it_url::get_multi got first url'); # UTF8SAFE ok(strpos($pages['b'], ''), 'it_url::get_multi got second url'); # UTF8SAFE is(count($pages), 2, 'it_url::get_multi no additional array elements'); diff --git a/tests/it_url_slow.t b/tests/it_url_slow.t index 1dc3d78..68d68c1 100755 --- a/tests/it_url_slow.t +++ b/tests/it_url_slow.t @@ -53,7 +53,7 @@ if (!$res || !$res2) handle_server( ok( - it_url::get(U('http://localhost:8000/repeat', 'string' => "abc", array('num' => 1024 * 1024))) == str_repeat("abc", 1024 * 1024), + it_url::get(U('http://localhost:8000/repeat', array('string' => "abc", 'num' => 1024 * 1024))) == str_repeat("abc", 1024 * 1024), 'it_url::get() handles large response' ) ); -- cgit v1.2.3 From 2e32e77ee60b599413903b3fbb7a4710b226dbfa Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 16:49:13 +0200 Subject: no longer need to correct buggy php line numbers --- it_debug.class | 3 --- 1 file changed, 3 deletions(-) diff --git a/it_debug.class b/it_debug.class index 6aab9eb..6a4c387 100644 --- a/it_debug.class +++ b/it_debug.class @@ -178,9 +178,6 @@ static function backtrace($p = array()) { if (($fn = $call['file']) && !it::match($p['skipfiles'], $call['file'])) { - if (!it::match('\.class|\.html', $call['file']) && @file_get_contents($call['file'], null, null, 0, 2) == "#!") - $call['line']++; # fix bug in php error line reporting - $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : "") . basename($fn); $result[] = $fn . ":" . $call['line']; -- cgit v1.2.3 From 79d5a50477ed74940484a5ca046dfa04adce1550 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 10 Aug 2015 19:01:25 +0200 Subject: empty array should not become null --- it.class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/it.class b/it.class index e6f8006..c5c1179 100644 --- a/it.class +++ b/it.class @@ -430,7 +430,7 @@ static function any2utf8($value, $errprefix = "") { foreach ($value as $idx => $v) $newarr[self::any2utf8($idx)] = is_string($v) || is_array($v) ? self::any2utf8($v, $errprefix) : $v; - $value = $newarr; + $value = (array)$newarr; } else if (is_string($value)) { -- cgit v1.2.3