From 65c16fdbeb441899e665363e1b8b24868f1d678c Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sun, 13 Aug 2006 23:39:57 +0000 Subject: [PATCH] - locateName should not change the state/error, can be used to test an entry --- ext/zip/php_zip.c | 14 +++++++++++++- ext/zip/tests/oo_namelocate.phpt | 16 ++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index f4a72c2e57..6b18bc9e07 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1126,6 +1126,7 @@ ZIPARCHIVE_METHOD(locateName) char *name; int name_len; long flags = 0; + long idx = -1; if (!this) { RETURN_FALSE; @@ -1142,7 +1143,18 @@ ZIPARCHIVE_METHOD(locateName) RETURN_FALSE; } - RETURN_LONG((long)zip_name_locate(intern, (const char *)name, flags)) + idx = (long)zip_name_locate(intern, (const char *)name, flags); + + if (idx<0) { + /* reset the error */ + if (intern->error.str) { + _zip_error_fini(&intern->error); + } + _zip_error_init(&intern->error); + RETURN_FALSE; + } else { + RETURN_LONG(idx); + } } /* }}} */ diff --git a/ext/zip/tests/oo_namelocate.phpt b/ext/zip/tests/oo_namelocate.phpt index ccfa3a9d8d..3010037e71 100644 --- a/ext/zip/tests/oo_namelocate.phpt +++ b/ext/zip/tests/oo_namelocate.phpt @@ -31,15 +31,15 @@ if (!$zip->open($file)) { exit('failed'); } -echo $zip->locateName('entry1.txt') . "\n"; -echo $zip->locateName('eNtry2.txt') . "\n"; -echo $zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE) . "\n"; -echo $zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR) . "\n"; +var_dump($zip->locateName('entry1.txt')); +var_dump($zip->locateName('eNtry2.txt')); +var_dump($zip->locateName('eNtry2.txt', ZIPARCHIVE::FL_NOCASE)); +var_dump($zip->locateName('enTRy2d.txt', ZIPARCHIVE::FL_NOCASE|ZIPARCHIVE::FL_NODIR)); $zip->close(); ?> --EXPECTF-- -0 --1 -1 -2 +int(0) +bool(false) +int(1) +int(2) -- 2.50.1