Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7a28a44

Browse filesBrowse files
committed
[BrowserKit] Emulate back/forward browser navigation
1 parent 549af73 commit 7a28a44
Copy full SHA for 7a28a44

File tree

2 files changed

+16
-2
lines changed
Filter options

2 files changed

+16
-2
lines changed

‎src/Symfony/Component/BrowserKit/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ CHANGELOG
77
* [BC BREAK] The request method is dropped from POST to GET when the response
88
status code is 301.
99

10+
* [BC BREAK] Client will skip redirects during history navigation
11+
(back and forward calls) according to W3C Browsers recommendation
12+
1013
3.2.0
1114
-----
1215

‎src/Symfony/Component/BrowserKit/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Client.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ abstract class Client
4242

4343
private $maxRedirects = -1;
4444
private $redirectCount = 0;
45+
private $redirects = array();
4546
private $isMainRequest = true;
4647

4748
/**
@@ -328,6 +329,8 @@ public function request($method, $uri, array $parameters = array(), array $files
328329
}
329330

330331
if ($this->followRedirects && $this->redirect) {
332+
$this->redirects[spl_object_hash($this->history->current())] = true;
333+
331334
return $this->crawler = $this->followRedirect();
332335
}
333336

@@ -430,7 +433,11 @@ protected function createCrawlerFromContent($uri, $content, $type)
430433
*/
431434
public function back()
432435
{
433-
return $this->requestFromRequest($this->history->back(), false);
436+
do {
437+
$request = $this->history->back();
438+
} while (array_key_exists(spl_object_hash($request), $this->redirects));
439+
440+
return $this->requestFromRequest($request, false);
434441
}
435442

436443
/**
@@ -440,7 +447,11 @@ public function back()
440447
*/
441448
public function forward()
442449
{
443-
return $this->requestFromRequest($this->history->forward(), false);
450+
do {
451+
$request = $this->history->forward();
452+
} while (array_key_exists(spl_object_hash($request), $this->redirects));
453+
454+
return $this->requestFromRequest($request, false);
444455
}
445456

446457
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.