Skip to content

Commit

Permalink
Fix render bug for protected sites (#3549)
Browse files Browse the repository at this point in the history
- Real-time site-toggle disable according isProtected logic and `enableForProtectedPages` option.
- tab.isProtected should not use `enableForProtectedPages` option as it doesn't get up-to-date data and will return the old value.
- Resolves #3548
  • Loading branch information
Gusted committed Sep 1, 2020
1 parent 13bf1ce commit 71fb947
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/background/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class Extension {
private getURLInfo(url: string): TabInfo {
const {DARK_SITES} = this.config;
const isInDarkList = isURLInList(url, DARK_SITES);
const isProtected = !(this.user.settings.enableForProtectedPages || canInjectScript(url));
const isProtected = !canInjectScript(url);
return {
url,
isInDarkList,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/popup/components/site-toggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function SiteToggleButton({data, tab, actions}: ExtWrapper & {tab
}
}
const toggleHasEffect = (
data.isEnabled &&
data.settings.enableForProtectedPages ||
!tab.isProtected
);
const pdf = isPDF(tab.url);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function isPDF(url: string) {
}

export function isURLEnabled(url: string, userSettings: UserSettings, {isProtected, isInDarkList}) {
if (isProtected && userSettings.enableForProtectedPages) {
if (isProtected && !userSettings.enableForProtectedPages) {
return false;
}
if (isPDF(url) && userSettings.enableForPDF) {
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/url.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ test('URL is enabled', () => {
'https://chrome.google.com/webstore',
{siteList: ['chrome.google.com'], siteListEnabled: [], applyToListedOnly: true, enableForProtectedPages: true} as UserSettings,
{isProtected: true, isInDarkList: false},
)).toBe(false);
)).toBe(true);
expect(isURLEnabled(
'https://chrome.google.com/webstore',
{siteList: [], siteListEnabled: [], applyToListedOnly: false, enableForProtectedPages: false} as UserSettings,
{isProtected: true, isInDarkList: false},
)).toBe(true);
)).toBe(false);
expect(isURLEnabled(
'https://chrome.google.com/webstore',
{siteList: ['chrome.google.com'], siteListEnabled: [], applyToListedOnly: false, enableForProtectedPages: true} as UserSettings,
Expand All @@ -86,7 +86,7 @@ test('URL is enabled', () => {
'https://microsoftedge.microsoft.com/addons',
{siteList: ['microsoftedge.microsoft.com'], siteListEnabled: [], applyToListedOnly: true, enableForProtectedPages: true} as UserSettings,
{isProtected: true, isInDarkList: false},
)).toBe(false);
)).toBe(true);
expect(isURLEnabled(
'https://duckduckgo.com',
{siteList: [], siteListEnabled: [], applyToListedOnly: false, enableForProtectedPages: true} as UserSettings,
Expand Down

0 comments on commit 71fb947

Please sign in to comment.