From fff6d9bd8e686a662e1c0b321c1f71026995f8ba Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 9 Mar 2020 18:01:36 +1300 Subject: [PATCH] Revert "Make $civicrm_paths less sensitive to trailing slashes. Add tests." This is currently causing breakage on wordpress sites where clean urls are not enabled. Compare the 2 urls below - the top one has an extra (breaking) slash added by this PR. I propose a quick revert & patch release followed by 'the right' fix at a slower pace /wp-admin/admin.php/?page=CiviCRM&q=civicrm%2Fupgrade%2Fqueue%2Fajax%2FrunNext /wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fupgrade%2Fqueue%2Fajax%2FrunNext This reverts commit 232fdd3dfac4ea09749d7f178818139514e48e38. --- Civi/Core/Paths.php | 2 +- tests/phpunit/Civi/Core/PathsTest.php | 88 --------------------------- 2 files changed, 1 insertion(+), 89 deletions(-) delete mode 100644 tests/phpunit/Civi/Core/PathsTest.php diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index 651fb29cdc..e2e1ff62ea 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -255,7 +255,7 @@ class Paths { return $value; } - $value = rtrim($this->getVariable($defaultContainer, 'url'), '/') . '/' . $value; + $value = $this->getVariable($defaultContainer, 'url') . $value; if ($preferFormat === 'relative') { $parsed = parse_url($value); diff --git a/tests/phpunit/Civi/Core/PathsTest.php b/tests/phpunit/Civi/Core/PathsTest.php deleted file mode 100644 index bd5cbbd07d..0000000000 --- a/tests/phpunit/Civi/Core/PathsTest.php +++ /dev/null @@ -1,88 +0,0 @@ -getPath()` - // and `Civi::paths()->getUrl()` work as expected. - - // Trailing-slash configurations -- these all worked before current patch - - $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo/bar', '/var/www/files/foo/bar']; - $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo/', '/var/www/files/foo/']; - $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo', '/var/www/files/foo']; - $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/.', '/var/www/files/']; - - $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo/bar', 'http://example.com/files/foo/bar']; - $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo/', 'http://example.com/files/foo/']; - $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo', 'http://example.com/files/foo']; - $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/.', 'http://example.com/files/']; - - $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo/bar', 'http://example.com:8080/foo/bar']; - $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo/', 'http://example.com:8080/foo/']; - $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo', 'http://example.com:8080/foo']; - $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/.', 'http://example.com:8080/']; - - // Trimmed-slash configurations -- some of these worked before, and some misbehaved. Now fixed. - - $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo/bar', '/var/www/files/foo/bar']; - $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo/', '/var/www/files/foo/']; - $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo', '/var/www/files/foo']; - $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/.', '/var/www/files/']; - - $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo/bar', 'http://example.com/files/foo/bar']; - $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo/', 'http://example.com/files/foo/']; - $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo', 'http://example.com/files/foo']; - $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/.', 'http://example.com/files/']; - - $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo/bar', 'http://example.com:8080/foo/bar']; - $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo/', 'http://example.com:8080/foo/']; - $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo', 'http://example.com:8080/foo']; - $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/.', 'http://example.com:8080/']; - - return $exs; - } - - /** - * @param $varName - * @param $varType - * @param $varValue - * @param $inputExpr - * @param $expectValue - * @dataProvider getExamples - */ - public function testExamples($varName, $varType, $varValue, $inputExpr, $expectValue) { - global $civicrm_paths; - $civicrm_paths[$varName][$varType] = $varValue; - $func = ($varType === 'url') ? 'getUrl' : 'getPath'; - - $paths = new Paths(); - $paths->register($varName, function() { - return ['path' => 'FIXME-PATH', 'url' => 'FIXME-URL']; - }); - - $actualValue = call_user_func([$paths, $func], $inputExpr); - $this->assertEquals($expectValue, $actualValue); - - unset($civicrm_paths[$varName][$varType]); - } - - public function testGetUrl_ImplicitBase() { - $p = \Civi::paths(); - $cmsRoot = rtrim($p->getVariable('cms.root', 'url'), '/'); - - $this->assertEquals("$cmsRoot/foo/bar", $p->getUrl('foo/bar')); - $this->assertEquals("$cmsRoot/foo/", $p->getUrl('foo/')); - $this->assertEquals("$cmsRoot/foo", $p->getUrl('foo')); - } - -} -- 2.25.1