Support Article
'+' in the URL encodes to '%2B' on launching URL in new window
Summary
The '+' character in the URL encodes to '%2B' on click when using the open URL in the new window action.
Error Messages
Not Applicable.
Steps to Reproduce
- Have an external URL which contains '+' in the URL
- Configure on click event for an image or icon with 'OpenURLInWindow'
Root Cause
A defect in Pegasystems’ code or rules.
Resolution
Perform the following local-change:Add the following code in UserWorkForm and in the UserWorkForm uncheck the check box 'omit extra spaces':
<script>
$(document).ready(function() {
if (SafeURL) {
SafeURL.prototype.toQueryString = function(bDisableEncode, bUnEscapeBefore) {
var result1 = "";
var result2 = "";
var bEncode = true;
var bUnEscape = true;
if (arguments.length > 0) {
bEncode = !bDisableEncode;
}
if (arguments.length > 1) {
bUnEscape = bUnEscapeBefore;
}
// ensure pzHarnessID is in the request if it's possible to obtain
// it from the DOM and if this request is an activity or stream request
if (document &&
('pyActivity' in this.hashtable || 'pyStream' in this.hashtable)) {
var reqURI = this.hashtable["pxReqURI"];
// insert Harness ID if no absolute external URI is specified
if (!reqURI // no URI specified, must be local
|| reqURI[0] == ' ' || reqURI[0] == '/' // URI is relative to this host
|| (reqURI.indexOf(document.location.host) > -1) // URI specifies this host
) {
var idFromDOM = document.getElementById("pzHarnessID");
if (idFromDOM && !this.hashtable.pzHarnessID) {
this.hashtable.pzHarnessID = idFromDOM.value;
}
}
}
for (var i in this.hashtable) {
if (i != "pxReqURI") {
var value = this.hashtable[i];
if (typeof(value) == 'string') {
// itkis, 11/24/08. unescape call commented out - was wrecking havoc with URL encryption. For
// example string %80% would get converted into %80 into %. Consequent encoding would convert it
// into %C2%80%25 - an error.
// if(this.mayBeEscaped(value)) {
//debugger;
// }
if (bUnEscape) {
value = unescape(value);
}
if (bEncode) {
value = encodeURIComponent(value); //all values are encoded only once
if(typeof value == "string") {
value = value.replace(/%2B/gm, "+");
}
}
}
if (i == "pyActivity" || i == "pyStream") {
//result1= i + "=" + this.hashtable[i];
result1 = i + "=" + value;
} else if (this.hashtable[i] != null) {
//result2 += "&" + i + "=" + this.hashtable[i];
if (typeof(value) == "object" && value.name == "safeURL") {
value = value.toURL();
}
result2 += "&" + i + "=" + value;
}
}
}
if (result1 == "") {
if (result2 == "") {
return "";
} else {
return result2.substring(1, result2.length); //remove the leading '&'
}
} else {
return result1 + result2;
}
}
}
});
</script>
Published December 8, 2018 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.