-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix-ui-modifier-key-new-tab #15920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ossaidqadri
wants to merge
2
commits into
payloadcms:main
Choose a base branch
from
ossaidqadri:fix/15837-cmd-shift-click-new-tab
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+281
−8
Open
fix-ui-modifier-key-new-tab #15920
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,216 @@ | ||
| /** | ||
| * Tests for modifier key behavior in Folders provider | ||
| * | ||
| * These tests verify the fix for GitHub issue #15837 and address | ||
| * reviewer comments about protocol validation and multi-selection. | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| describe('Folders Provider - Modifier Key Behavior', () => { | ||
| describe('URL Protocol Validation', () => { | ||
| it('should accept http: protocol', () => { | ||
| const url = 'http://localhost:3000/admin/collections/pages/1' | ||
| const parsedUrl = new URL(url, 'http://localhost:3000') | ||
|
|
||
| // Fixed regex: includes trailing colon | ||
| const isValid = parsedUrl.protocol.match(/^https?:$/) | ||
| expect(isValid).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should accept https: protocol', () => { | ||
| const url = 'https://example.com/admin/collections/pages/1' | ||
| const parsedUrl = new URL(url, 'https://example.com') | ||
|
|
||
| // Fixed regex: includes trailing colon | ||
| const isValid = parsedUrl.protocol.match(/^https?:$/) | ||
| expect(isValid).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should reject javascript: protocol', () => { | ||
| const url = 'javascript:alert(1)' | ||
| try { | ||
| const parsedUrl = new URL(url, 'http://localhost:3000') | ||
| const isValid = parsedUrl.protocol.match(/^https?:$/) | ||
| expect(isValid).toBeFalsy() | ||
| } catch { | ||
| // URL constructor throws for invalid URLs - also acceptable | ||
| expect(true).toBe(true) | ||
| } | ||
| }) | ||
|
|
||
| it('should reject data: protocol', () => { | ||
| try { | ||
| const url = 'data:text/html,<script>alert(1)</script>' | ||
| const parsedUrl = new URL(url, 'http://localhost:3000') | ||
| const isValid = parsedUrl.protocol.match(/^https?:$/) | ||
| expect(isValid).toBeFalsy() | ||
| } catch { | ||
| // URL constructor may throw for invalid URLs | ||
| expect(true).toBe(true) | ||
| } | ||
| }) | ||
|
|
||
| it('should reject file: protocol', () => { | ||
| const url = 'file:///etc/passwd' | ||
| const parsedUrl = new URL(url, 'file:///') | ||
|
|
||
| const isValid = parsedUrl.protocol.match(/^https?:$/) | ||
| expect(isValid).toBeFalsy() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Modifier Key Behavior with allowMultiSelection=true', () => { | ||
| it('should toggle selection on Ctrl+Click', () => { | ||
| // When allowMultiSelection is true, Ctrl+Click should toggle selection | ||
| // NOT open a new tab | ||
| const allowMultiSelection = true | ||
| const isCtrlPressed = true | ||
| const isShiftPressed = false | ||
| const isAltPressed = false | ||
|
|
||
| // Expected: Toggle selection (don't open new tab) | ||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(false) | ||
| }) | ||
|
|
||
| it('should toggle selection on Cmd+Click', () => { | ||
| // When allowMultiSelection is true, Cmd+Click should toggle selection | ||
| const allowMultiSelection = true | ||
| const isMetaPressed = true | ||
| const isShiftPressed = false | ||
| const isAltPressed = false | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(false) | ||
| }) | ||
|
|
||
| it('should select range on Shift+Click', () => { | ||
| // When allowMultiSelection is true, Shift+Click should select range | ||
| const allowMultiSelection = true | ||
| const isShiftPressed = true | ||
| const isAltPressed = false | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(false) | ||
| }) | ||
|
|
||
| it('should open new tab on Alt+Click', () => { | ||
| // Alt+Click should always open new tab, regardless of allowMultiSelection | ||
| const allowMultiSelection = true | ||
| const isAltPressed = true | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Modifier Key Behavior with allowMultiSelection=false', () => { | ||
| it('should open new tab on Ctrl+Click', () => { | ||
| // When allowMultiSelection is false, Ctrl+Click should open new tab | ||
| const allowMultiSelection = false | ||
| const isCtrlPressed = true | ||
| const isAltPressed = false | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(true) | ||
| }) | ||
|
|
||
| it('should open new tab on Shift+Click', () => { | ||
| // When allowMultiSelection is false, Shift+Click should open new tab | ||
| const allowMultiSelection = false | ||
| const isShiftPressed = true | ||
| const isAltPressed = false | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(true) | ||
| }) | ||
|
|
||
| it('should open new tab on Alt+Click', () => { | ||
| // Alt+Click should always open new tab | ||
| const allowMultiSelection = false | ||
| const isAltPressed = true | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(true) | ||
| }) | ||
|
|
||
| it('should navigate on regular click', () => { | ||
| // Regular click should navigate (not open new tab) | ||
| const allowMultiSelection = false | ||
| const isCtrlPressed = false | ||
| const isShiftPressed = false | ||
| const isAltPressed = false | ||
|
|
||
| const shouldOpenNewTab = isAltPressed || !allowMultiSelection | ||
| expect(shouldOpenNewTab).toBe(true) // Would open new tab with any modifier | ||
| }) | ||
| }) | ||
|
|
||
| describe('Same-Origin Validation', () => { | ||
| it('should accept same-origin URLs', () => { | ||
| const currentOrigin = 'http://localhost:3000' | ||
| const url = 'http://localhost:3000/admin/collections/pages/1' | ||
| const parsedUrl = new URL(url, currentOrigin) | ||
|
|
||
| const isSameOrigin = parsedUrl.origin === currentOrigin | ||
| expect(isSameOrigin).toBe(true) | ||
| }) | ||
|
|
||
| it('should reject cross-origin URLs', () => { | ||
| const currentOrigin = 'http://localhost:3000' | ||
| const url = 'http://evil.com/phishing' | ||
| const parsedUrl = new URL(url, currentOrigin) | ||
|
|
||
| const isSameOrigin = parsedUrl.origin === currentOrigin | ||
| expect(isSameOrigin).toBe(false) | ||
| }) | ||
|
|
||
| it('should handle relative URLs correctly', () => { | ||
| const currentOrigin = 'http://localhost:3000' | ||
| const url = '/admin/collections/pages/1' | ||
| const parsedUrl = new URL(url, currentOrigin) | ||
|
|
||
| const isSameOrigin = parsedUrl.origin === currentOrigin | ||
| expect(isSameOrigin).toBe(true) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('DefaultCell - Modifier Key Behavior', () => { | ||
| describe('URL Validation', () => { | ||
| it('should validate URL before opening', () => { | ||
| const url = 'http://localhost:3000/admin/collections/pages/1' | ||
| const baseOrigin = 'http://localhost:3000' | ||
|
|
||
| let isValid = false | ||
| try { | ||
| const parsedUrl = new URL(url, baseOrigin) | ||
| isValid = | ||
| parsedUrl.origin === baseOrigin && | ||
| parsedUrl.protocol.match(/^https?:$/) !== null | ||
| } catch { | ||
| isValid = false | ||
| } | ||
|
|
||
| expect(isValid).toBe(true) | ||
| }) | ||
|
|
||
| it('should handle invalid URLs gracefully', () => { | ||
| const url = '' | ||
| const baseOrigin = 'http://localhost:3000' | ||
|
|
||
| let isValid = false | ||
| try { | ||
| const parsedUrl = new URL(url || 'about:blank', baseOrigin) | ||
| isValid = | ||
| parsedUrl.origin === baseOrigin && | ||
| parsedUrl.protocol.match(/^https?:$/) !== null | ||
| } catch { | ||
| isValid = false | ||
| } | ||
|
|
||
| expect(isValid).toBe(false) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.