php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62844
Patch parse_url_relative_scheme2 revision 2012-08-19 23:31 UTC by ajf at ajf dot me
Patch parse_url_relative_scheme revision 2012-08-19 23:10 UTC by ajf at ajf dot me

Patch parse_url_relative_scheme for URL related Bug #62844

Patch version 2012-08-19 23:10 UTC

Return to Bug #62844 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: ajf@ajf.me

From 0cdda05eff4ed7c697bcd77a0d5ecb70597b3efe Mon Sep 17 00:00:00 2001
From: Andrew Faulds <ajf@ajf.me>
Date: Mon, 20 Aug 2012 00:03:55 +0100
Subject: [PATCH] bug #62844; relative URL schemes in parse_url()

---
 .../tests/url/parse_url_relative_scheme.phpt       |   11 +++++++++++
 ext/standard/url.c                                 |    2 ++
 2 files changed, 13 insertions(+)
 create mode 100644 ext/standard/tests/url/parse_url_relative_scheme.phpt

diff --git a/ext/standard/tests/url/parse_url_relative_scheme.phpt b/ext/standard/tests/url/parse_url_relative_scheme.phpt
new file mode 100644
index 0000000..7c8952d
--- /dev/null
+++ b/ext/standard/tests/url/parse_url_relative_scheme.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Test parse_url() function: Checks relative URL schemes (e.g. "//example.com")
+--FILE--
+<?php
+var_dump(parse_url('//example.org'));
+--EXPECT--
+array(1) {
+  ["host"]=>
+  string(11) "example.org"
+}
+
diff --git a/ext/standard/url.c b/ext/standard/url.c
index 0555c7b..f1e48a1 100644
--- a/ext/standard/url.c
+++ b/ext/standard/url.c
@@ -204,6 +204,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
 		} else {
 			goto just_path;
 		}
+	} else if (*s == '/' && *(s+1) == '/') { /* same-scheme (relative) URL */
+		s += 2;
 	} else {
 		just_path:
 		ue = s + length;
-- 
1.7.9.5

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 21:01:28 2024 UTC