URIError: Wrong URI Sequence?

Below is the error code c URIError: malformed URI sequence?, when in the URL string there is a character %similar to 60% - Completedwhere I need to extract the parameter value, for example.http://some-external-server.com/info?progress=60%%20-%20Completed

   <SCRIPT type="text/javascript">
            function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                results = regex.exec(location.search);
                return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }
    </SCRIPT>

I have no control over the server and you need to process the output on my html page.

+4
source share
1 answer

I think you need the URI to encode the percent sign as "% 25"

http://some-external-server.com/info?progress=60%25%20-%20Completed 

[EDIT]

I think you could do something like this:

var str = "60%%20-%20completed";
var uri_encoded = str.replace(/%([^\d].)/, "%25$1");
console.log(str); // "60%25%20-%20completed"
var decoded = decodeURIComponent(uri_encoded);
console.log(decoded); // "60% - completed"
+3
source

All Articles