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/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; } } 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' + ); } } 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