Skip to content

Commit

Permalink
Merge pull request #63 from kasparsd/release/1.3.1
Browse files Browse the repository at this point in the history
Release 1.3.1
  • Loading branch information
kasparsd committed Apr 24, 2020
2 parents a7e8a63 + 2b8a4c4 commit b4943bc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions readme.txt.md
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/UriRules.php
Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/php/WidgetContextTargetByUrlTest.php
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions tests/php/WidgetContextTest.php
Expand Up @@ -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'
);
}

}
2 changes: 1 addition & 1 deletion widget-context.php
Expand Up @@ -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
Expand Down

0 comments on commit b4943bc

Please sign in to comment.