JavaScript - encodeURI results in illegal JSON

41 views Asked by At

I'm working on a program that invokes a PowerShell script using a custom protocol. So far, I reached the situation that the mechanisms are working as needed except for one small thing. I found a temporary solution but its ugliness is far beyond my tolerance.

The JavaScript piece of code I'm using follows:

:
:
var l_Request_JSON_Str = '{"Request":"Do_1","Par_1":"blabla"}' ;
var l_Test_URL = 'MyProt:MyApp?Command=' + l_Request_JSON_Str ;

l_Test_URL = encodeURI(l_Test_URL) ;

var l_Tempo_Element       = document.createElement("a") ;
l_Tempo_Element.setAttribute    ("id"   , "Invoke_Custom_Prototol"           ) ;
l_Tempo_Element.setAttribute    ("href" , l_Test_URL                         ) ;
l_Tempo_Element.addEventListener("click", function (e) { e.stopPropagation()}) ;

l_Tempo_Element.click() ;

l_Tempo_Element.remove() ;

:
:

The value returned by encodeURI is:

fdmyalbs:MyApp?Command=%7B%22Request%22:%22Get_Albums_List%22,%22Folder%22:%22blablaFolder%22%7D

which, as can be seen, includes the comma between the two elements of the JSON.

When this string is delivered to the PowerShell script, the same comma character is replaced by a linefeed/carriage-return/speace character (did not check it, but the PowerShell console shows the second element of the JSON in a separate line).

For the time being, I change the code such that the string to be sent to the script is:

fdmyalbs:MyApp?Command=%7B%22Request%22:%22Get_Albums_List%22@@@%22Folder%22:%22blablaFolder%22%7D

At the PowerShell script, I replace @@@ with a comma character and everything works as required.

Why is the comma being replaced in the transaction from the JavaScript and the PS script?

0

There are 0 answers