Skip to content

Commit ef94f3f

Browse files
committed
fix: remove parameter $relative which does not work
1 parent 15b3ff3 commit ef94f3f

2 files changed

Lines changed: 12 additions & 45 deletions

File tree

system/Helpers/url_helper.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,14 @@ function previous_url(bool $returnObject = false)
183183
/**
184184
* URL String
185185
*
186-
* Returns the path part of the current URL
187-
*
188-
* @param bool $relative Whether the resulting path should be relative to baseURL
186+
* Returns the path part (relative to baseURL) of the current URL
189187
*/
190-
function uri_string(bool $relative = false): string
188+
function uri_string(): string
191189
{
192-
return $relative
193-
? ltrim(Services::request()->getPath(), '/')
194-
: Services::request()->getUri()->getPath();
190+
// The value of Services::request()->getUri()->getPath() is overridden
191+
// by IncomingRequest constructor. If we use it here, the current tests
192+
// in CurrentUrlTest will fail.
193+
return ltrim(Services::request()->getPath(), '/');
195194
}
196195
}
197196

@@ -583,7 +582,7 @@ function url_is(string $path): bool
583582
{
584583
// Setup our regex to allow wildcards
585584
$path = '/' . trim(str_replace('*', '(\S)*', $path), '/ ');
586-
$currentPath = '/' . trim(uri_string(true), '/ ');
585+
$currentPath = '/' . trim(uri_string(), '/ ');
587586

588587
return (bool) preg_match("|^{$path}$|", $currentPath, $matches);
589588
}

tests/system/Helpers/URLHelper/CurrentUrlTest.php

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testCurrentURLWithPortInSubfolder()
163163
$this->assertSame(8080, $uri->getPort());
164164
}
165165

166-
public function testUriStringAbsolute()
166+
public function testUriString()
167167
{
168168
$_SERVER['HTTP_HOST'] = 'example.com';
169169
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';
@@ -183,18 +183,7 @@ private function setService(string $uri): void
183183
Services::injectMock('request', $request);
184184
}
185185

186-
public function testUriStringRelative()
187-
{
188-
$_SERVER['HTTP_HOST'] = 'example.com';
189-
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';
190-
191-
$uri = 'http://example.com/assets/image.jpg';
192-
$this->setService($uri);
193-
194-
$this->assertSame('assets/image.jpg', uri_string(true));
195-
}
196-
197-
public function testUriStringNoTrailingSlashAbsolute()
186+
public function testUriStringNoTrailingSlash()
198187
{
199188
$_SERVER['HTTP_HOST'] = 'example.com';
200189
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';
@@ -207,33 +196,12 @@ public function testUriStringNoTrailingSlashAbsolute()
207196
$this->assertSame('assets/image.jpg', uri_string());
208197
}
209198

210-
public function testUriStringNoTrailingSlashRelative()
211-
{
212-
$_SERVER['HTTP_HOST'] = 'example.com';
213-
$_SERVER['REQUEST_URI'] = '/assets/image.jpg';
214-
215-
$this->config->baseURL = 'http://example.com';
216-
217-
$uri = 'http://example.com/assets/image.jpg';
218-
$this->setService($uri);
219-
220-
$this->assertSame('assets/image.jpg', uri_string(true));
221-
}
222-
223-
public function testUriStringEmptyAbsolute()
199+
public function testUriStringEmpty()
224200
{
225201
$uri = 'http://example.com/';
226202
$this->setService($uri);
227203

228-
$this->assertSame('/', uri_string());
229-
}
230-
231-
public function testUriStringEmptyRelative()
232-
{
233-
$uri = 'http://example.com/';
234-
$this->setService($uri);
235-
236-
$this->assertSame('', uri_string(true));
204+
$this->assertSame('', uri_string());
237205
}
238206

239207
public function testUriStringSubfolderAbsolute()
@@ -260,7 +228,7 @@ public function testUriStringSubfolderRelative()
260228
$uri = 'http://example.com/subfolder/assets/image.jpg';
261229
$this->setService($uri);
262230

263-
$this->assertSame('assets/image.jpg', uri_string(true));
231+
$this->assertSame('assets/image.jpg', uri_string());
264232
}
265233

266234
public function urlIsProvider()

0 commit comments

Comments
 (0)