cvs: php4 /ext/standard url.c
| From: | John Donagher | Date: | Fri, 24 Aug 2001 02:21:17 +0000 |
| Subject: | cvs: php4 /ext/standard url.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7043@lists.php.net to get a copy of this message | ||
jdonagher Thu Aug 23 22:21:17 2001 EDT
Modified files:
/php4/ext/standard url.c
Log:
Don't try and search a 0-length string. This allows parse_url() to correctly
parse a non-pathed URI, i.e. 'scheme://'
Index: php4/ext/standard/url.c
diff -u php4/ext/standard/url.c:1.44 php4/ext/standard/url.c:1.45
--- php4/ext/standard/url.c:1.44 Fri Aug 17 03:41:20 2001
+++ php4/ext/standard/url.c Thu Aug 23 22:21:16 2001
@@ -15,7 +15,7 @@
| Author: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
-/* $Id: url.c,v 1.44 2001/08/17 07:41:20 sterling Exp $ */
+/* $Id: url.c,v 1.45 2001/08/24 02:21:16 jdonagher Exp $ */
#include <stdlib.h>
#include <string.h>
@@ -114,32 +114,34 @@
regfree(&re); /* free the old regex */
- if ((cerr=regcomp(&re,
"^(([^@:]+)(:([^@:]+))?@)?((\\[([^]]+)\\])|([^:@]+))(:([^:@]+))?", REG_EXTENDED))
- || (err=regexec(&re, result, 11, subs, 0))) {
- STR_FREE(ret->scheme);
- STR_FREE(ret->path);
- STR_FREE(ret->query);
- STR_FREE(ret->fragment);
- efree(ret);
- efree(result);
- /*php_error(E_WARNING, "Unable to compile regex: %d\n", err);*/
- if (!cerr) regfree(&re);
- return NULL;
- }
- /* now deal with all of the results */
- if (subs[2].rm_so != -1 && subs[2].rm_so < length) {
- ret->user = estrndup(result + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
- }
- if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
- ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
- }
- if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
- ret->host = estrndup(result + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
- } else if (subs[8].rm_so != -1 && subs[8].rm_so < length) {
- ret->host = estrndup(result + subs[8].rm_so, subs[8].rm_eo - subs[8].rm_so);
- }
- if (subs[10].rm_so != -1 && subs[10].rm_so < length) {
- ret->port = (unsigned short) strtol(result + subs[10].rm_so, NULL, 10);
+ if (length) {
+ if ((cerr=regcomp(&re,
"^(([^@:]+)(:([^@:]+))?@)?((\\[([^]]+)\\])|([^:@]+))(:([^:@]+))?", REG_EXTENDED))
+ || (err=regexec(&re, result, 11, subs, 0))) {
+ STR_FREE(ret->scheme);
+ STR_FREE(ret->path);
+ STR_FREE(ret->query);
+ STR_FREE(ret->fragment);
+ efree(ret);
+ efree(result);
+ /*php_error(E_WARNING, "Unable to compile regex: %d\n", err);*/
+ if (!cerr) regfree(&re);
+ return NULL;
+ }
+ /* now deal with all of the results */
+ if (subs[2].rm_so != -1 && subs[2].rm_so < length) {
+ ret->user = estrndup(result + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
+ }
+ if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
+ ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
+ }
+ if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
+ ret->host = estrndup(result + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
+ } else if (subs[8].rm_so != -1 && subs[8].rm_so < length) {
+ ret->host = estrndup(result + subs[8].rm_so, subs[8].rm_eo - subs[8].rm_so);
+ }
+ if (subs[10].rm_so != -1 && subs[10].rm_so < length) {
+ ret->port = (unsigned short) strtol(result + subs[10].rm_so, NULL, 10);
+ }
}
efree(result);
}