A
A
Andrey Strelkov2020-10-30 22:36:42
JavaScript
Andrey Strelkov, 2020-10-30 22:36:42

Why is the space character handled with an error in Javascript?

Good afternoon, I ran into a problem when creating my own protocol URI
Namely, it is necessary that links of the explorer:// type be opened as if by an explorer, in other words, the content of the link after explorer:// was sent to the explorer as a context

. Thus, a registry entry was created describing the new protocol, and the purpose of this entry was to describe the action of the system / browsers when clicking on this link, the action was as follows:

mshta javascript:new(ActiveXObject)('WScript.Shell').Run(decodeURIComponent(escape('%1'.substr(9)))),window.close()


Registry file

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\explorer]
"URL Protocol"=""
@="Explorer"

[HKEY_CURRENT_USER\SOFTWARE\Classes\explorer\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\explorer\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\explorer\shell\open\command]
@="mshta javascript:new(ActiveXObject)('WScript.Shell').Run(decodeURIComponent(escape('%1'.substr(9)))),window.close()"


The problem is that this script successfully executes on the following links

<a href="explorer:\\\\DESKTOP-9NVI47I\\temp\\word">word</a>
<a href="explorer:\\\\DESKTOP-9NVI47I\\temp\\кириллица">кириллица</a>
<a href="explorer:\\\\DESKTOP-9NVI47I\\temp\\файл-с-(кириллицей).txt">файл-с-(кириллицей).txt</a>


but breaks like this
<a href="explorer:\\\\DESKTOP-9NVI47I\\temp\\один пробел">один пробел</a><br>


those. when a space appears :/ When you click on
this link, an error occurs

5f9c68e435cdb229906778.png

and if you continue execution, the following window will appear . about encodeno, and ready for decoding from the side of the script . If we fix the script a little in the registry, I made it so that the finished result is displayed after all the link transformations

5f9c68eb77f1f959166675.png




mshta javascript:new(ActiveXObject)('WScript.Shell').Run(alert(decodeURIComponent(escape('%1'.substr(9))))),window.close()


That will be the following result

5f9c69b6b9929214010027.png

. What looks more than a working one, like, if you execute

5f9c6a9c0da76576721723.png

it, it will open successfully :/ And here I find it difficult to understand what could be the reason. Why is he not confused by the Cyrillic alphabet, special characters, etc., but he stumbled about the space :///

Please tell me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-10-31
@strelkov_av

I would venture to suggest that spaces in WScript.Shell.Run play the same role they play in cmd - separating command line options. Try using quotes for escaping, i.e.

mshta javascript:new(ActiveXObject)('WScript.Shell').Run('"'+decodeURIComponent(escape('%1'.substr(9)))+'"'),window.close()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question