Ticket #1228 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

OpenLayers.Util.removeItem does not remove consecutive items

Reported by: openlayers Owned by:
Priority: trivial Milestone: 2.6 Release
Component: Util Version: 2.5
Keywords: Cc: ccljacobson@…
State: Complete

Description

The OpenLayers.Util.removeItem function does not remove all instances of the item from the array when the items are consecutive. For example, calling OpenLayers.Util.removeItem([1, 1], 1) results in the array [1] when it should be [].

There are several ways to fix the problem, the easiest way would be to decrement the variable i after the call to array.splice(i,1);

Attachments

1228.patch Download (1.6 KB) - added by pspencer 6 years ago.
patch to test case and code to fix the issue.

Change History

Changed 6 years ago by openlayers

  • priority changed from minor to trivial

Changed 6 years ago by pspencer

agreed. attaching patch with updated test case that demonstrates the problem and a patch to OpenLayers.Util.removeItem that fixes it by looping over the array backwards.

Changed 6 years ago by pspencer

patch to test case and code to fix the issue.

Changed 6 years ago by pspencer

  • state set to Review

Changed 6 years ago by crschmidt

  • state changed from Review to Commit

Couple minor syntax comments for general OL commits:

  • For loop should be "len >= 0"
  • no need to split len out into a seperate assignment -- doing it in the init will work fine
  • Your patch paths aren't relative to the OL root: in general, create a patch via 'cd openlayers_checkout; svn diff > file'

The first two should be changed when you commit. This appears to be a simple and obvious bug, and I can't imagine that anyone is depending on this broken behavior.

Changed 6 years ago by pagameba

  • keywords removeItem removed
  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [5543]) Small patch to removeItem so that all instances of a value in the array are removed, even if they are consecutive by reversing the order in which the array is enumerated. Updated tests and checked in Safari 3, FF2. (closes #1228).

Note: See TracTickets for help on using tickets.