Skip to content

Conversation

@maniktyagi04
Copy link

Description

Fixes #8269

When removeListener is called with a listener that doesn't exist, indexOf returns -1, and splice(-1, 1) removes the last element in the array. This PR adds a check to only splice if the listener is found.

Changes

  • Added index validation in removeListener method
  • Added test case to verify the fix

Testing

  • ✅ All existing tests pass (51 tests in core)
  • ✅ New test case verifies that removing a non-existent listener doesn't affect other listeners

Impact

  • Type: Bug fix
  • Breaking: No
  • Platforms: Web (affects WebPlugin implementations)

Before

// Removing a non-existent listener would remove the last listener
await plugin.addListener('test', listener1);
await plugin.addListener('test', listener2);
await removeListener('test', listener3); // listener2 gets removed ❌

After

// Removing a non-existent listener does nothing
await plugin.addListener('test', listener1);
await plugin.addListener('test', listener2);
await removeListener('test', listener3); // No change ✅

When removeListener is called with a listener that doesn't exist,
indexOf returns -1, and splice(-1, 1) removes the last element.
This fix adds a check to only splice if the listener is found.

Fixes: Incorrect listener removal when listener not found
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 4, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 5, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 6, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 7, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 8, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 9, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 10, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 11, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 12, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 13, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 14, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 15, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 16, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 17, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 18, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 19, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 20, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 21, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 22, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 23, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 24, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 25, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 26, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): WebPlugin removeListener removes wrong listener when target not found

1 participant