Why is Javascript handling space character with error?

  • 0
    Good afternoon, I ran into a problem while creating my own protocol URI.
    Namely, it is necessary that links like explorer: // open as if by a conductor, i.e. in other words, the content of the link after explorer: // was sent to the explorer as 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
    "URL Protocol"=""
    @="mshta javascript:new(ActiveXObject)('WScript.Shell').Run(decodeURIComponent(escape('%1'.substr(9)))),window.close()"

    The problem is that this script successfully runs 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 it 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

    and if you continue execution, there will be the following window

    It seems to be clear that the space is indicated as % 20 , i.e. about encodeno, and ready to decode from the script side

    If you slightly correct the script in the registry, I made it so that the finished result is displayed after all the transformations of the link.

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

    That will be the following result.

    Which looks more than working kind of like if you execute it

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

    Tell me please
    JavaScript Anonymous, Feb 27, 2019

  • 1 Answers
  • 0
    I would venture to suggest that spaces in WScript.Shell.Run play the same role as they play in cmd - separating command line parameters. Try using quotation marks for escaping i.e.

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

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!