2014-09-26 33 views
0

如我所料,我需要在使用它調用API之前對URI組件進行編碼,但當它沿着該線到達我們的服務器時,我們的後端框架(tapestry)太早轉換空間:Java URLEncoding/Decoding URL Spaces with dashes

我想,如果我將URI%20更改爲$ 0020,它就可以工作。所以下面的代碼適用於Chrome和Firefox,並將%轉換爲$ 00。

function furtherEncode(uriComp) { 
    var nonSafe = encodeURIComponent(uriComp); 
    return nonSafe.replace(/%/g, "$00"); 
} 

在Internet Explorer 11(和IE10)中,它不會進行替換。

我試過/\x25/g/%/g以及"$00"'$00'但無濟於事。

任何幫助將不勝感激。

+0

這就是爲什麼你必須禁止空格。 – 2014-09-26 14:27:46

回答

0

你需要有兩個美元符號像這裏(IE和Chrome測試):

"%".replace(/%/g, "$$00") /// returns "$00" 

見文檔瀏覽:docs

相關部分「指定字符串作爲參數」下定義:

$$ | Inserts a "$". 
$n | Where n or nn are decimal digits, inserts the nth parenthesized submatch string, provided the first argument was a RegExp object 
+0

謝謝修復它。 – mearing 2014-09-26 16:07:49