简体   繁体   English

在JavaScript中转义反斜杠

[英]Escaping backslash inside javascript

<script type="text/javascript"> 
    console.log(#Fileurl#);
    jQuery.ajax({
        url: "http://xyz:8800/aaa/bbb/ccc",
        type:'POST',
        dataType: 'JSON',
        data:{"file":"#Fileurl#"},
        success: function(data) {
            console.log(data);
        }
    });
</script>

This is the javascript code inside a coldfusion page. 这是Coldfusion页面内的javascript代码。 If I try to print "Fileurl" outside script,output is perfect. 如果我尝试在脚本之外打印“ Fileurl”,则输出是完美的。

output : D:\\abc\\FLV\\238550_605_orion.mp4. 输出:D:\\ abc \\ FLV \\ 238550_605_orion.mp4。

But inside javascript output is, 但是在javascript输出中,

D:abcFLV238550_605_orion.mp4. d:abcFLV238550_605_orion.mp4。

Actually we want to send url to delete the particular file.Reply is highly appreciated. 实际上我们想发送url来删除特定文件。

Hi there is no way to do the task in javascript. 嗨,没有办法用javascript做任务。 So instead of 所以代替

use ColdFusion's jsstringformat to convert the Fileurl to 使用ColdFusion的jsstringformatFileurl转换为

D:\\abc\\FLV\\238550_605_orion.mp4 d:\\ ABC \\ FLV \\ 238550_605_orion.mp4

console.log("<cfoutput>JSStringFormat(Fileurl)</cfoutput>");

If you're using ColdFusion 10+, you should use encodeForJavaScript() instead of JSStringFormat() . 如果您使用的是ColdFusion 10+,则应使用encodeForJavaScript()而不是JSStringFormat() In addition, by putting the path to a network file in the client-side code, you're opening yourself up to a Path Traversal attack. 此外,通过将网络文件的路径放在客户端代码中,您将自己面临路径遍历攻击。

The user could manipulate the JavaScript to point to different files and folders than what you're intending. 用户可以操纵JavaScript来指向与您想要的文件和文件夹不同的文件和文件夹。 If you're passing this to a delete function, you could be in for a world of trouble. 如果将其传递给删除函数,则可能会遇到麻烦。 Why not pass some file ID instead? 为什么不传递一些文件ID?

Backslash has special meaning, you have to escape that. 反斜杠具有特殊的含义,您必须逃避它。 You can try to double the backslashes, or use proper url format like file://path/to/file with forward slashes. 您可以尝试将反斜杠加倍,或使用正确的url格式,例如file:// path / to / file和正斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM