无终止的字符串常量-mshta:javascript [英] Unterminated string constant-mshta:javascript

查看:111
本文介绍了无终止的字符串常量-mshta:javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我试图使用mshta从javascript中获取快速警报框,但是我发现了一些奇怪的问题,并且我不存在任何问题.从某种意义上讲,这就是我想要实现的目标:

Recently I was trying to get a quick alert box from javascript using mshta but I noticed something strange and I have no ideea what the problem is. This is,in a way,what I was trying to achieve:

mshta javascript:alert("The file was stored here:\"C:\\folder_with_space_ _.txt");

它给出的错误是该帖子标题中的错误(char 57).我尝试了以下几种组合:

The error it gives is the one in the title of this post(char 57).I tried a combination of things and:

//code that works:
mshta javascript:alert("The file was stored here:\"sdadasd");
mshta javascript:alert("The file was stored here:\"\" sdadasd");

//error-notice the space;error on char 35
mshta javascript:alert("The file was stored here:\" sdasds");

当双引号的数量为奇数时,它似乎给出了错误,但是:

It looks like it's giving error when the number of double-quotes is odd,but:

//error
mshta javascript:alert("The file was stored here:\" \"sdadasd");

我试图在浏览器控制台中执行相同的操作,但它确实起作用.我相信是某种解析器错误,该如何解决?(我正在考虑使用fromCharCode直接插入双引号).

I tried to do the same in a browser console and it worked. I believe is some kind of parser-error.How can I fix it?(I am thinking of using fromCharCode to directly insert the double quote).

注意:这些命令是从cmd运行的.

Note: the commands were run from cmd.

推荐答案

我将以我要使用的命令版本开始,并解释其工作原理:

I'll start off with the version of the command that I got to work, and I'll explain why it works:

mshta "javascript:alert('The file was stored here:\x22C:\\folder_with_space_ _.txt');"

第一个也是最重要的一点是,我们将一个参数传递给mshta.exe(要执行的JavaScript命令),因此我们应将整个参数用双引号引起来.这样可以防止将空格视为参数定界符.

The first and perhaps most important point is that we are passing a single argument to mshta.exe (the JavaScript command to execute), so we should surround that entire argument in double quotes. This prevents the space from being treated as an argument delimiter.

第二点是,似乎没有办法在实际的JavaScript命令中使用双引号.根据问题在批处理脚本中转义双引号,没有标准的在cmd的双引号内转义双引号.显然,mshta.exe不支持""\"(或者至少我无法使它们工作).我建议在注释中遵循Teemu的建议,并在JavaScript代码中仅将单引号用于字符串定界符.如果要在字符串中包含双引号字符,请使用十六进制文字\x22.

The second point is that there doesn't seem to be a way to have double quotes inside the actual JavaScript commands. According to the question Escaping Double Quotes in Batch Script, there is no standard for escaping double quotes inside double quotes for cmd. Apparently, mshta.exe doesn't honor "" or \" (or at least, I couldn't get them to work). I suggest following Teemu's suggestion in the comments and use single quotes only for string delimiter in the JavaScript code. If, inside a string, you want to include a double quote character, use the hex literal \x22.

这篇关于无终止的字符串常量-mshta:javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆