--- contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java.orig	2007-06-27 11:17:34.000000000 -0700
+++ contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java	2007-07-21 16:20:14.000000000 -0700
@@ -126,6 +126,13 @@
     public String toString() {
       return value.toString();
     }
+
+    public boolean equals(Object other) {
+      if (this == other) return true;
+      if (!(other instanceof KeyValue)) return false;
+      KeyValue okv = (KeyValue) other;
+      return this.key.equals(okv.key) && this.value.equals(okv.value);
+    }
   }
 
   /**
@@ -149,6 +156,9 @@
    */
   public void setValue(String key, String value) {
     if (n_values.containsKey(key)) {
+      if(active.contains(n_values.get(key)))
+        active.remove(active.indexOf(n_values.get(key)));
+
       ((KeyValue) n_values.get(key)).setValue(value);
     } else {
       n_values.put(key, new KeyValue(key, value));
@@ -303,9 +313,21 @@
 
   public Object clone(){
     SearchForm newForm=new SearchForm(new HashMap());
-    newForm.active.addAll(active);
     newForm.o_values.putAll(o_values);
-    newForm.n_values.putAll(n_values);
+
+    // make sure we have a deep copy of all KeyValue objects which can be modified
+    Iterator j = n_values.entrySet().iterator();
+    while (j.hasNext()) {
+      KeyValue kv = (KeyValue) ((Map.Entry) j.next()).getValue();
+      newForm.n_values.put(kv.getKey(), new KeyValue(kv.getKey(), kv.getValue()));
+    }
+
+    Iterator i = active.iterator();
+    while (i.hasNext()) {
+      KeyValue kv = (KeyValue) i.next();
+      newForm.active.add(new KeyValue(kv.getKey(), kv.getValue()));
+    }
+
     return newForm;
   }
 
