CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Core/URI.php: Parse_url() fails if a segment contains "foo:digit"

Open bitbucket-import opened this issue 15 years ago • 3 comments

== Details == Type: Function stops script File: core/URI.php:176

== Description == Parse_url will fail on URIs with segments that look like "foo:number". It is the colon that appears to be causing it (probably because parse_url thinks that it is a port number, and thus malformed).

== Replication == Go to a URL like this: http://localhost/ci/foo/bar/test:2/

== Proposed fix == Substitute ":" with a tag, parse the URI, and then reinstate the ":" again.

== Original code == {{{

!php

$uri = parse_url($uri, PHP_URL_PATH); }}}

== Workaround == {{{

!php

if (preg_match('/:\d/', $uri)) { $uri = str_replace('{C0L0N}',':',parse_url(str_replace(':','{C0L0N}',$uri),PHP_URL_PATH)); } else $uri = parse_url($uri, PHP_URL_PATH); }}}

bitbucket-import avatar Aug 19 '11 14:08 bitbucket-import

http://www.php.net/manual/en/function.parse-url.php

Note: This function doesn't work with relative URLs.

The usage of parse_url() in CI is wrong.

kenjis avatar Aug 21 '11 12:08 kenjis

Wouldn't this fix replace a segment thar contains the exact text {COLON} with :?

Razican avatar Feb 14 '12 09:02 Razican

As PHP_URL_PATH is used, the simplest solution is to just prepend a dummy scheme and hostname to $uri.

WanWizard avatar Jun 13 '12 22:06 WanWizard