Skip to content

Commit

Permalink
Merge pull request #62 from kasparsd/fix/url-query-param-match
Browse files Browse the repository at this point in the history
Fix path matcher for URIs with query params
  • Loading branch information
kasparsd authored Apr 24, 2020
2 parents a7640de + 8d27fd5 commit 112def8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion readme.txt.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Specify URLs to ignore even if they're matched by any of the other context rules

### 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 visbility rule.
- 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.
- Introduce [premium support](https://widgetcontext.com/pro) to help maintain the plugin. Subscribe now to get the PRO version of the Widget Context for free when it's launched!

### 1.2.0 (August 20, 2019)
Expand Down
3 changes: 2 additions & 1 deletion src/UriRules.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'
);
}

}

0 comments on commit 112def8

Please sign in to comment.