d1727a7299087e0e936222db77097cfd936ddc2e
chmalee
  Thu Jun 12 14:55:42 2025 -0700
Don't double encode items on the url if they are already encoded, refs #35799

diff --git src/hg/js/utils.js src/hg/js/utils.js
index 854040b1e20..ef3599683a1 100644
--- src/hg/js/utils.js
+++ src/hg/js/utils.js
@@ -1164,34 +1164,40 @@
         if (count++ > 0) {
             retVal += "&";
         }
         var val = varHash[aVar];
         if (typeof(val) === 'string'
         && val.length >= 2
         && val.indexOf('[') === 0
         && val.lastIndexOf(']') === (val.length - 1)) {
             var vals = val.substr(1,val.length - 2).split(',');
             /* jshint loopfunc: true */// function inside loop works and replacement is awkward.
             $(vals).each(function (ix) {
                 if (ix > 0)
                     retVal += "&";
                 retVal += aVar + "=" + encodeURIComponent(this);
             });
+        } else {
+            let decoded = decodeURIComponent(val);
+            if (decoded.length < val.length) {
+                // val was already encoded, don't re-encode
+                retVal += aVar + "=" + val;
             } else {
                 retVal += aVar + "=" + encodeURIComponent(val);
             }
         }
+    }
     return retVal;
 }
 
 function getAllVarsAsUrlData(obj)  // DEAD CODE?
 {
 // Returns a string in the form of var1=val1&var2=val2... for all inputs and selects in an obj
 // If obj is undefined then obj is document!
     return varHashToQueryString(getAllVars(obj));
 }
 
 /*
 function popupBox(popit, content, popTitle)
 {
 // Kicks off a Modal Dialog for the provided content.
 // Requires jquery-ui.js