-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[BrowserKit] Emulate back/forward browser navigation #22341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
637abad
to
46b8e7b
Compare
05f2c01
to
44df302
Compare
As this is a new feature please rebase this on the master and change the pull-request target. Also this is missing some tests. Status: needs work |
@sstok , thanks for your comment. PR target is changed to master. as for tests - I'm waiting for implementation review/approval. if it's done correctly I will add missing tests |
@@ -328,6 +340,8 @@ public function request($method, $uri, array $parameters = array(), array $files | |||
} | |||
|
|||
if ($this->followRedirects && $this->redirect) { | |||
$this->redirects[] = spl_object_hash($this->history->current()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use the hash as key rather than value. the array is used to check whether it contains a given hash, and O(1)
is better than than O(n)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
protected $followRedirects = true; | ||
protected $browserNavigation = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use private visibility for any new property. We don't want to make them extension points yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return $this->requestFromRequest($this->history->back(), false); | ||
do { | ||
$request = $this->history->back(); | ||
} while ($this->browserNavigation && in_array(spl_object_hash($request), $this->redirects)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we reach the beginning of the history ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
History object will throw \LogicException('You are already on the first page.');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the behavior will be the same
f321c80
to
4c8af71
Compare
I'd like to ask if this is something that browsers do contrary to the standard ... or if this is the behavior proposed by the related standard. That way we'll know if this is a new feature or a bug. Thanks! |
@javiereguiluz , maybe we can check this document: https://www.w3.org/TR/html5/browsers.html#history |
Assuming the BrowserKit client should conform to that standard it's a bug, as
Joint session history is defined as (emphasis moved):
As a redirect is no fully active Document object navigation should bypass it, hence it's a bug. But also a BC breaking bug as there may be tons of tests out there explicitly going back twice in history to circumvent this behavior. |
@curry684 , thanks for you findings! Sine this is a bugfix should I rebase this PR to 2.7 branch? |
As it might break existing tests, I think this needs to be merged in master, even if this is a bug fix. |
* | ||
* @param bool $browserNavigation Whether to emulate browser navigation | ||
*/ | ||
public function browserNavigation($browserNavigation = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not make it configurable as browsers don't make this configurable either. I understand that you probably want to be able to keep BC here. But I don't think that this is a good idea. The current behavior is wrong and we should fix it. What needs to be done though is to add a note in the CHANGELOG/UPGRADE files to document this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Given the possibly severe BC breaks I'd also recommend considering this a functionality change, hence master. |
Tests and docs added, comments applied. Also, I changed |
@@ -328,6 +329,8 @@ public function request($method, $uri, array $parameters = array(), array $files | |||
} | |||
|
|||
if ($this->followRedirects && $this->redirect) { | |||
$this->redirects[serialize($this->history->current())] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you consider spl_object_hash
instead of serialize? It should be way faster and less memory intensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above done by @e-moe explaining why it was changed.
Anything I can do to make this go forward? |
Thank you @e-moe. |
…e-moe) This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #22341). Discussion ---------- [BrowserKit] Emulate back/forward browser navigation | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22336 | License | MIT | Doc PR | CHANGELOG.md updated Hi all, please review this code for emulating back/forward browser navigation (skip redirects). If code is ok I will add tests and docs Commits ------- 680da44 [BrowserKit] Emulate back/forward browser navigation
Hi all, please review this code for emulating back/forward browser navigation (skip redirects). If code is ok I will add tests and docs