From a00e5d7482c211b3637d1a631084cb7c3f2a2b70 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Fri, 24 Apr 2020 11:22:20 +0300 Subject: [PATCH 1/3] Assume that only query parameters can contain equal signs --- src/UriRules.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/UriRules.php b/src/UriRules.php index bdf4ae4..fd494af 100644 --- a/src/UriRules.php +++ b/src/UriRules.php @@ -39,7 +39,8 @@ public function rules() { */ public function has_rules_with_query_strings() { foreach ( $this->rules as $rule ) { - if ( false !== strpos( $rule, '?' ) ) { + // Assume that only query parameters can contain equal signs. + if ( false !== strpos( $rule, '=' ) ) { return true; } } From 8d27fd5baa6b97d61bd6896b1ac53819dc96f516 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Fri, 24 Apr 2020 11:23:55 +0300 Subject: [PATCH 2/3] Tests to cover the wildcard + query param combos --- tests/php/WidgetContextTargetByUrlTest.php | 13 +++++++++++++ tests/php/WidgetContextTest.php | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/tests/php/WidgetContextTargetByUrlTest.php b/tests/php/WidgetContextTargetByUrlTest.php index fef7970..90c90f7 100644 --- a/tests/php/WidgetContextTargetByUrlTest.php +++ b/tests/php/WidgetContextTargetByUrlTest.php @@ -116,7 +116,20 @@ public function testUrlQueryStrings() { ); } + public function testQueryStringsWithWildcards() { + $this->assertTrue( + $this->plugin->match_path( 'categoria-producte/cosmetica/?pwb-brand-filter=clarins', '*pwb-brand-filter=*' ), + 'Matching query param key with wrapping wildcards' + ); + + $this->assertTrue( + $this->plugin->match_path( 'producte/cosmetica?pwb-brand-filter=clarins', '*/cosmetica/?pwb-brand-filter=*' ), + 'Ignore trailing slashes on rule paths' + ); + } + public function testUrlSpecial() { + // Disregard things like utm_source and other tracking parameters. $this->assertTrue( $this->plugin->match_path( 'campaigns?cc=automotive', 'campaigns/' ), 'Ignore query string because no rules use it' diff --git a/tests/php/WidgetContextTest.php b/tests/php/WidgetContextTest.php index b1e74ba..8b717c8 100644 --- a/tests/php/WidgetContextTest.php +++ b/tests/php/WidgetContextTest.php @@ -50,6 +50,12 @@ public function testRequestPathResolver() { 'path-to-a/url.html', $this->plugin->path_from_uri( 'path-to-a/url.html' ) ); + + $this->assertEquals( + 'producte/cosmetica?pwb-brand-filter=clarins', + $this->plugin->path_from_uri( 'producte/cosmetica/?pwb-brand-filter=clarins' ), + 'Normalize the path by removing the trailing slash' + ); } } From 2b8a4c4c7a4c69ad1c56ded5accf7c20837195c3 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Fri, 24 Apr 2020 11:32:52 +0300 Subject: [PATCH 3/3] Bump version and add the changelog --- readme.txt.md | 4 ++++ widget-context.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/readme.txt.md b/readme.txt.md index dfcb5ac..0b5871c 100644 --- a/readme.txt.md +++ b/readme.txt.md @@ -65,6 +65,10 @@ Specify URLs to ignore even if they're matched by any of the other context rules ## Changelog +### 1.3.1 (April 24, 2020) + +- Bugfix: better support for URL rules with query parameters. + ### 1.3.0 (April 23, 2020) - Introduce the long-awaited "Exclude by URL" feature to prevent certain URLs from showing or hiding a widget when it's matched by any other visibility rule. diff --git a/widget-context.php b/widget-context.php index 567ab7b..0d0ee72 100644 --- a/widget-context.php +++ b/widget-context.php @@ -3,7 +3,7 @@ * Plugin Name: Widget Context * Plugin URI: https://widgetcontext.com * Description: Show or hide widgets depending on the section of the site that is being viewed. Configure the widget visibility rules under the individual widget settings. - * Version: 1.3.0 + * Version: 1.3.1 * Author: Kaspars Dambis * Author URI: https://widgetcontext.com * Text Domain: widget-context