Browse Source

Fix extensions always being defaulted.

Extensions should not magically be defaulted. Doing this makes
generating URLs unpredictable and annoying.

Refs #4771
Mark Story 11 years ago
parent
commit
5cddb90606
2 changed files with 34 additions and 2 deletions
  1. 2 2
      src/Routing/Router.php
  2. 32 0
      tests/TestCase/Routing/RouterTest.php

+ 2 - 2
src/Routing/Router.php

@@ -517,7 +517,7 @@ class Router {
 			'plugin' => null,
 			'controller' => null,
 			'action' => 'index',
-			'_ext' => null
+			'_ext' => null,
 		);
 		$here = $base = $output = $frag = null;
 
@@ -575,7 +575,7 @@ class Router {
 					'plugin' => $params['plugin'],
 					'controller' => $params['controller'],
 					'action' => 'index',
-					'_ext' => $params['_ext']
+					'_ext' => null
 				);
 			}
 

+ 32 - 0
tests/TestCase/Routing/RouterTest.php

@@ -1036,6 +1036,38 @@ class RouterTest extends TestCase {
 	}
 
 /**
+ * test url() when the current request has an extension.
+ *
+ * @return void
+ */
+	public function testUrlGenerationWithExtensionInCurrentRequest() {
+		Router::extensions('rss');
+		Router::scope('/', function ($r) {
+			$r->fallbacks();
+		});
+		$request = new Request();
+		$request->addParams(['controller' => 'Tasks', 'action' => 'index', '_ext' => 'rss']);
+		Router::pushRequest($request);
+
+		$result = Router::url(array(
+			'controller' => 'Tasks',
+			'action' => 'view',
+			1
+		));
+		$expected = '/tasks/view/1';
+		$this->assertEquals($expected, $result);
+
+		$result = Router::url(array(
+			'controller' => 'Tasks',
+			'action' => 'view',
+			1,
+			'_ext' => 'json'
+		));
+		$expected = '/tasks/view/1.json';
+		$this->assertEquals($expected, $result);
+	}
+
+/**
  * Test url generation with named routes.
  */
 	public function testUrlGenerationNamedRoute() {