Skip to content

HTTP/URI, CreateURIString yield unexpected result (http:/// instead of http://) #331

Description

@goFrendiAsgard

This code should add http:// prefix in front of every url, but apparently, it produce something different

<?php namespace App\Controllers;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\URI;

class MyController extends Controller{
    public function index(){        
		var_dump((string) new URI('entirely.different.com/subfolder'));
		var_dump((string) new URI('localhost/subfolder'));
		var_dump((string) new URI('localtest.me/subfolder'));
		var_dump((string) new URI('localhost/subfolder'));
    }
}

The output is:

home/gofrendi/public_html/No-CMS-2.0/application/CMS/Modules/Test/Controllers/MyController.php:12:string 'http:///entirely.different.com/subfolder' (length=40)

/home/gofrendi/public_html/No-CMS-2.0/application/CMS/Modules/Test/Controllers/MyController.php:13:string 'http:///localhost/subfolder' (length=27)

/home/gofrendi/public_html/No-CMS-2.0/application/CMS/Modules/Test/Controllers/MyController.php:14:string 'http:///localtest.me/subfolder' (length=30)

/home/gofrendi/public_html/No-CMS-2.0/application/CMS/Modules/Test/Controllers/MyController.php:15:string 'http:///localhost/subfolder' (length=27)

So, it add http:///' instead of http://'

Quick fix:
Change system/HTTP/URI.php on line 488 (function __toString) from this:

public function __toString()
	{
		return self::createURIString(
			$this->getScheme(), $this->getAuthority(), $this->getPath(), // Absolute URIs should use a "/" for an empty path
			$this->getQuery(), $this->getFragment()
		);
	}

into this

public function __toString()
	{
		$url = self::createURIString(
			$this->getScheme(), $this->getAuthority(), $this->getPath(), // Absolute URIs should use a "/" for an empty path
			$this->getQuery(), $this->getFragment()
		);
		return str_replace(':///', '://', $url);
	}

This fix the problem, but I guess there is something wrong with the algorithm. Probably someone want to check?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions