-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Ensure Accurate Detection of WordPress Previews via URL Query Pa…
…rameters (#1911) * fix(WordPressTemplate): fix issue when is-preview check is too greedy * chore(changeset): add changeset
- Loading branch information
Showing
5 changed files
with
35 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@faustwp/core': patch | ||
--- | ||
|
||
Bug: Fixes issue with review detection via query string is too greedy and catches non WP previews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Helper function to check if the URL is a WordPress preview | ||
export function isWordPressPreview(search: string) { | ||
const params = new URLSearchParams(search); | ||
return params.has('preview') && params.get('preview') === 'true'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/faustwp-core/tests/utils/isWordPressPreview.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isWordPressPreview } from '../../src/utils/isWordPressPreview'; | ||
|
||
describe('isWordPressPreview', () => { | ||
it('returns true if the search string contains preview=true', () => { | ||
expect(isWordPressPreview('?preview=true')).toBe(true); | ||
expect(isWordPressPreview('?foo=bar&preview=true')).toBe(true); | ||
}); | ||
|
||
it('returns false if the search string does not contain preview=true', () => { | ||
expect(isWordPressPreview('?preview=false')).toBe(false); | ||
expect(isWordPressPreview('?foo=bar')).toBe(false); | ||
expect(isWordPressPreview('?otpreview=true')).toBe(false); | ||
}); | ||
|
||
it('returns false if the search string is empty', () => { | ||
expect(isWordPressPreview('')).toBe(false); | ||
}); | ||
|
||
it('returns false if the preview parameter is not exactly true', () => { | ||
expect(isWordPressPreview('?preview=1')).toBe(false); | ||
expect(isWordPressPreview('?preview=yes')).toBe(false); | ||
}); | ||
}); |