开发者

vlc http interface file path encoding

I almost have this problem fixed but I'm building a remote on top of the VLC http interface and am having trouble encoding the & symbol.

For example I get a file name that looks like

C:\Users\Me\Music\Library\I Need a Doctor feat(Eminem & Skylar Grey)

But what VLC gets when I escape + url encode the file name is

C:\Users\Me\Music\Library\I Need a Doctor feat(Eminem

What do I do to fix this?

My pseudo-JavaScript:

function escapePa开发者_JAVA百科th(string){
    var fixed = "";
for(var i = 0; i < string.length; i++){
    if(string[i] == "\\"){
        fixed += "\\\\";
    }
    else if(string[i] == "&"){
        fixed += "%26"; // Doesn't work with or without this
    }
    else{
        fixed += string[i];
    }
}
    return encodeURIComponent(fixed);
}

I know it's bad but I cant get .replace() to work correctly. Curse my horrible knowledge of regex. I'll fix that later


Thanks to Marc B. It worked with some tweaks.

The final function ended up looking like:

return encodeURIComponent(str.replace(/!/g, '%21').replace(/'/g, '%27').replace(/\*/g, '%2A').replace(/\\/g, "\\\\"));

I only wish I knew why this works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜