Skip to content

Commit

Permalink
Merge pull request #322 from 10up/fix/321-deprecation-warning
Browse files Browse the repository at this point in the history
Fix PHP 8.1 deprecation warnings in `srm_validate_from_url()`.
  • Loading branch information
dkotter authored Jun 1, 2023
2 parents 0180f03 + 1d26bc1 commit b8e72ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions inc/classes/class-srm-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,18 @@ public function load_resources() {
* @return void
*/
public function srm_validate_from_url() {
$_wpnonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
if ( ! isset( $_GET['_wpnonce'] ) || ! isset( $_GET['from'] ) ) {
echo 0;
die();
}

$_wpnonce = sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) );
if ( ! wp_verify_nonce( $_wpnonce, 'srm-save-redirect-meta' ) ) {
echo 0;
die();
}

$from = filter_input( INPUT_GET, 'from', FILTER_SANITIZE_STRING );
$from = srm_sanitize_redirect_from( wp_unslash( $_GET['from'] ) );

/**
* SRM treats '/sample-page' and 'sample-page' equally.
Expand Down
15 changes: 15 additions & 0 deletions tests/cypress/integration/safe-redirect-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ describe('Test redirect rules', () => {
cy.verifyEndpointDead('wildcard-403-test/1', 'Test message for a 403 wildcard');
});

it('Can not create a duplicate redirect rule', () => {
cy.createRedirectRule(
'/duplicate-rule-test/',
'/hello-world/',
'Rule for testing duplicate rule creation.'
);

cy.visit('/wp-admin/post-new.php?post_type=redirect_rule');

cy.get('#srm_redirect_rule_from').click().clear().type('/duplicate-rule-test/');
cy.get('#srm_redirect_rule_to').click();

cy.get('.notice-error').should('contain', 'There is an existing redirect with the same Redirect From URL.');
});

it('Can die with a 403 header', () => {
cy.createRedirectRule(
'/403-test',
Expand Down

0 comments on commit b8e72ad

Please sign in to comment.