Safe Redirect Manager - Version 1.7.5

Version Description

(Sept. 9, 2014) = * Don't always lowercase matched parts in redirect to replace. Propsfrancescolaffi * Plugin icon/banner

Download this release

Release Info

Developer tlovett1
Plugin Icon 128x128 Safe Redirect Manager
Version 1.7.5
Comparing to
See all releases

Code changes from version 1.7.4 to 1.7.5

.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
  language: php
2
 
3
  php:
4
- - 5.2
5
  - 5.3
6
  - 5.4
7
 
1
  language: php
2
 
3
  php:
 
4
  - 5.3
5
  - 5.4
6
 
README.md CHANGED
@@ -1,4 +1,4 @@
1
- Safe Redirect Manager
2
  ==============
3
 
4
  A WordPress plugin to safely and easily manage your website's HTTP redirects.
1
+ Safe Redirect Manager [![Build Status](https://travis-ci.org/tlovett1/Safe-Redirect-Manager.svg?branch=master)](https://travis-ci.org/tlovett1/Safe-Redirect-Manager)
2
  ==============
3
 
4
  A WordPress plugin to safely and easily manage your website's HTTP redirects.
assets/banner-772x250.png ADDED
Binary file
assets/icon-256x256.png ADDED
Binary file
images/icon32x32.png DELETED
Binary file
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: tlovett1, tollmanz, taylorde, 10up, jakemgold, danielbachhuber, Ve
3
  Tags: http redirects, redirect manager, url redirection, safe http redirection, multisite redirects
4
  Requires at least: 3.1
5
  Tested up to: 4.0
6
- Stable tag: 1.7.4
7
 
8
  Safely and easily manage your website's HTTP redirects.
9
 
@@ -24,6 +24,10 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
24
 
25
  == Changelog ==
26
 
 
 
 
 
27
  = 1.7.4 (Sept. 5, 2014) =
28
  * Fix case sensitivity redirection bug.
29
  * Add more unit tests
3
  Tags: http redirects, redirect manager, url redirection, safe http redirection, multisite redirects
4
  Requires at least: 3.1
5
  Tested up to: 4.0
6
+ Stable tag: 1.7.5
7
 
8
  Safely and easily manage your website's HTTP redirects.
9
 
24
 
25
  == Changelog ==
26
 
27
+ = 1.7.5 (Sept. 9, 2014) =
28
+ * Don't always lowercase matched parts in redirect to replace. Props[francescolaffi](https://github.com/francescolaffi)
29
+ * Plugin icon/banner
30
+
31
  = 1.7.4 (Sept. 5, 2014) =
32
  * Fix case sensitivity redirection bug.
33
  * Add more unit tests
safe-redirect-manager.php CHANGED
@@ -3,8 +3,8 @@
3
  Plugin Name: Safe Redirect Manager
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
- Author: Taylor Lovett (10up LLC), VentureBeat
7
- Version: 1.7.4
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
@@ -202,10 +202,6 @@ class SRM_Safe_Redirect_Manager {
202
  if ( $this->is_plugin_page() ) {
203
  ?>
204
  <style type="text/css">
205
- #icon-tools {
206
- background: url("<?php echo plugins_url( 'images/icon32x32.png', __FILE__ ); ?>") no-repeat top left !important;
207
- margin-right: 0;
208
- }
209
  #visibility, .view-switch, .posts .inline-edit-col-left .inline-edit-group {
210
  display: none;
211
  }
@@ -800,9 +796,9 @@ class SRM_Safe_Redirect_Manager {
800
  $requested_path = esc_url_raw( $_SERVER['REQUEST_URI'] );
801
  $requested_path = stripslashes( $requested_path );
802
 
803
- $unslashed_requested_path = untrailingslashit( $requested_path );
804
- if ( empty( $unslashed_requested_path ) ){
805
- $unslashed_requested_path = '/';
806
  }
807
 
808
  /**
@@ -811,11 +807,22 @@ class SRM_Safe_Redirect_Manager {
811
  */
812
  $parsed_site_url = parse_url( site_url() );
813
  if ( isset( $parsed_site_url['path'] ) && '/' != $parsed_site_url['path'] ) {
814
- $unslashed_requested_path = preg_replace( '@' . $parsed_site_url['path'] . '@i', '', $unslashed_requested_path, 1 );
815
  }
816
 
817
  // Allow redirects to be filtered
818
- $redirects = apply_filters( 'srm_registered_redirects', $redirects, $unslashed_requested_path );
 
 
 
 
 
 
 
 
 
 
 
819
 
820
  foreach ( (array)$redirects as $redirect ) {
821
 
@@ -827,25 +834,24 @@ class SRM_Safe_Redirect_Manager {
827
  $status_code = $redirect['status_code'];
828
  $enable_regex = ( isset( $redirect['enable_regex'] ) ) ? $redirect['enable_regex'] : false;
829
 
830
- if ( apply_filters( 'srm_case_insensitive_redirects', true ) ) {
831
- $unslashed_requested_path = strtolower( $unslashed_requested_path );
832
- $redirect_from = strtolower( $redirect_from );
833
- }
834
-
835
  // check if requested path is the same as the redirect from path
836
  if ( $enable_regex ) {
837
- $matched_path = preg_match( '@' . $redirect_from . '@', $unslashed_requested_path );
838
  } else {
839
- $matched_path = ( $unslashed_requested_path == $redirect_from );
 
 
 
 
840
 
841
  // check if the redirect_from ends in a wildcard
842
  if ( !$matched_path && (strrpos( $redirect_from, '*' ) === strlen( $redirect_from ) - 1) ) {
843
  $wildcard_base = substr( $redirect_from, 0, strlen( $redirect_from ) - 1 );
844
 
845
  // mark as match if requested path matches the base of the redirect from
846
- $matched_path = (substr( $unslashed_requested_path, 0, strlen( $wildcard_base ) ) == $wildcard_base);
847
  if ( (strrpos( $redirect_to, '*' ) == strlen( $redirect_to ) - 1 ) ) {
848
- $redirect_to = rtrim( $redirect_to, '*' ) . ltrim( substr( $unslashed_requested_path, strlen( $wildcard_base ) ), '/' );
849
  }
850
  }
851
  }
@@ -860,12 +866,12 @@ class SRM_Safe_Redirect_Manager {
860
 
861
  // Allow for regex replacement in $redirect_to
862
  if ( $enable_regex ) {
863
- $redirect_to = preg_replace( '@' . $redirect_from . '@', $redirect_to, $unslashed_requested_path );
864
  }
865
 
866
  $sanitized_redirect_to = esc_url_raw( $redirect_to );
867
 
868
- do_action( 'srm_do_redirect', $unslashed_requested_path, $sanitized_redirect_to, $status_code );
869
 
870
  if ( defined( 'PHPUNIT_SRM_TESTSUITE' ) && PHPUNIT_SRM_TESTSUITE ) {
871
  // Don't actually redirect if we are testing
3
  Plugin Name: Safe Redirect Manager
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
+ Author: Taylor Lovett (10up)
7
+ Version: 1.7.5
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
202
  if ( $this->is_plugin_page() ) {
203
  ?>
204
  <style type="text/css">
 
 
 
 
205
  #visibility, .view-switch, .posts .inline-edit-col-left .inline-edit-group {
206
  display: none;
207
  }
796
  $requested_path = esc_url_raw( $_SERVER['REQUEST_URI'] );
797
  $requested_path = stripslashes( $requested_path );
798
 
799
+ $requested_path = untrailingslashit( $requested_path );
800
+ if ( empty( $requested_path ) ){
801
+ $requested_path = '/';
802
  }
803
 
804
  /**
807
  */
808
  $parsed_site_url = parse_url( site_url() );
809
  if ( isset( $parsed_site_url['path'] ) && '/' != $parsed_site_url['path'] ) {
810
+ $requested_path = preg_replace( '@' . $parsed_site_url['path'] . '@i', '', $requested_path, 1 );
811
  }
812
 
813
  // Allow redirects to be filtered
814
+ $redirects = apply_filters( 'srm_registered_redirects', $redirects, $requested_path );
815
+
816
+ // Allow for case insensitive redirects
817
+ $case_insensitive = apply_filters( 'srm_case_insensitive_redirects', true );
818
+ if ( $case_insensitive ) {
819
+ $regex_flag = 'i';
820
+ // normalized path is used for matching but not for replace
821
+ $normalized_requested_path = strtolower( $requested_path );
822
+ } else {
823
+ $regex_flag = '';
824
+ $normalized_requested_path = $requested_path;
825
+ }
826
 
827
  foreach ( (array)$redirects as $redirect ) {
828
 
834
  $status_code = $redirect['status_code'];
835
  $enable_regex = ( isset( $redirect['enable_regex'] ) ) ? $redirect['enable_regex'] : false;
836
 
 
 
 
 
 
837
  // check if requested path is the same as the redirect from path
838
  if ( $enable_regex ) {
839
+ $matched_path = preg_match( '@' . $redirect_from . '@' . $regex_flag, $requested_path );
840
  } else {
841
+ if ( $case_insensitive ) {
842
+ $redirect_from = strtolower( $redirect_from );
843
+ }
844
+
845
+ $matched_path = ( $normalized_requested_path == $redirect_from );
846
 
847
  // check if the redirect_from ends in a wildcard
848
  if ( !$matched_path && (strrpos( $redirect_from, '*' ) === strlen( $redirect_from ) - 1) ) {
849
  $wildcard_base = substr( $redirect_from, 0, strlen( $redirect_from ) - 1 );
850
 
851
  // mark as match if requested path matches the base of the redirect from
852
+ $matched_path = (substr( $normalized_requested_path, 0, strlen( $wildcard_base ) ) == $wildcard_base);
853
  if ( (strrpos( $redirect_to, '*' ) == strlen( $redirect_to ) - 1 ) ) {
854
+ $redirect_to = rtrim( $redirect_to, '*' ) . ltrim( substr( $requested_path, strlen( $wildcard_base ) ), '/' );
855
  }
856
  }
857
  }
866
 
867
  // Allow for regex replacement in $redirect_to
868
  if ( $enable_regex ) {
869
+ $redirect_to = preg_replace( '@' . $redirect_from . '@' . $regex_flag, $redirect_to, $requested_path );
870
  }
871
 
872
  $sanitized_redirect_to = esc_url_raw( $redirect_to );
873
 
874
+ do_action( 'srm_do_redirect', $requested_path, $sanitized_redirect_to, $status_code );
875
 
876
  if ( defined( 'PHPUNIT_SRM_TESTSUITE' ) && PHPUNIT_SRM_TESTSUITE ) {
877
  // Don't actually redirect if we are testing
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
tests/test-core.php CHANGED
@@ -395,4 +395,45 @@ class SRMTestCore extends WP_UnitTestCase {
395
 
396
  $this->assertTrue( ! $redirected );
397
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  }
395
 
396
  $this->assertTrue( ! $redirected );
397
  }
398
+
399
+ /**
400
+ * Test that replace (both wildcard and regex) doesn't change the casing on the matched part
401
+ *
402
+ * @since 1.7.5
403
+ */
404
+ public function testReplaceCasing() {
405
+ global $safe_redirect_manager;
406
+
407
+ // with wildcard
408
+ $_SERVER['REQUEST_URI'] = '/myfiles1/FooBar.JPEG';
409
+ $redirected = false;
410
+ $redirect_to = '/images1/*';
411
+ $safe_redirect_manager->create_redirect( '/myfiles1/*', $redirect_to );
412
+
413
+ add_action( 'srm_do_redirect', function( $requested_path, $redirected_to, $status_code ) use ( &$redirect_to, &$redirected ) {
414
+ if ( $redirected_to === '/images1/FooBar.JPEG' ) {
415
+ $redirected = true;
416
+ }
417
+ }, 10, 3 );
418
+
419
+ $safe_redirect_manager->action_parse_request();
420
+
421
+ $this->assertTrue( $redirected );
422
+
423
+ // with regex
424
+ $_SERVER['REQUEST_URI'] = '/myfiles2/FooBar.JPEG';
425
+ $redirected = false;
426
+ $redirect_to = '/images2/$1';
427
+ $safe_redirect_manager->create_redirect( '/myfiles2/(.*\.jpe?g)', $redirect_to, 301, true );
428
+
429
+ add_action( 'srm_do_redirect', function( $requested_path, $redirected_to, $status_code ) use ( &$redirect_to, &$redirected ) {
430
+ if ( $redirected_to === '/images2/FooBar.JPEG' ) {
431
+ $redirected = true;
432
+ }
433
+ }, 10, 3 );
434
+
435
+ $safe_redirect_manager->action_parse_request();
436
+
437
+ $this->assertTrue( $redirected );
438
+ }
439
  }