diff --git a/misc/collapse.js b/misc/collapse.js
index 512ff2f..065639f 100644
--- a/misc/collapse.js
+++ b/misc/collapse.js
@@ -60,7 +60,7 @@ Drupal.behaviors.collapse = {
       // Expand fieldset if there are errors inside, or if it contains an
       // element that is targeted by the URI fragment identifier.
       var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : '';
-      if ($fieldset.find('.error' + anchor).length) {
+      if ($fieldset.find('.error' + anchor.replace(/[=%;,\/]/g, "_")).length) {
         $fieldset.removeClass('collapsed');
       }
 
