@@ -191,14 +191,40 @@ Deno.test("format pass example in README.md", () => {
191191 "denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md" ,
192192 ) ;
193193
194+ const fileUrl = path . win32 . toFileUrl ( "C:\\Users\\John Titor\\test.git" ) ;
195+ assertEquals (
196+ fileUrl . pathname ,
197+ "/C:/Users/John%20Titor/test.git" ,
198+ ) ;
194199 assertEquals (
195200 format ( {
196201 scheme : "denops" ,
197- expr : path . win32 . toFileUrl ( "C:\\Users\\John Titor\\test.git" ) . pathname ,
202+ expr : fileUrl . pathname ,
198203 } ) ,
199- "denops:///C:/Users/John%20Titor /test.git" ,
204+ "denops:///C:/Users/John%2520Titor /test.git" ,
200205 ) ;
201206} ) ;
207+ Deno . test ( "format encodes '%' in 'expr'" , ( ) => {
208+ const src = {
209+ scheme : "denops" ,
210+ expr : "/hello%world" ,
211+ } ;
212+ const dst = format ( src ) ;
213+ const exp = "denops:///hello%25world" ;
214+ assertEquals ( dst , exp ) ;
215+ } ) ;
216+ Deno . test ( "format encodes '%' in 'params'" , ( ) => {
217+ const src = {
218+ scheme : "denops" ,
219+ expr : "/absolute/path/to/worktree" ,
220+ params : {
221+ foo : "%foo" ,
222+ } ,
223+ } ;
224+ const dst = format ( src ) ;
225+ const exp = "denops:///absolute/path/to/worktree;foo=%25foo" ;
226+ assertEquals ( dst , exp ) ;
227+ } ) ;
202228
203229Deno . test ( "parse throws exception when 'expr' contains unusable characters" , ( ) => {
204230 const src = "denops:///<>|?*" ;
@@ -375,16 +401,52 @@ Deno.test("parse pass example in README.md", () => {
375401 } ,
376402 ) ;
377403
378- const bufname = parse ( "denops:///C:/Users/John%20Titor /test.git" ) ;
404+ const bufname = parse ( "denops:///C:/Users/John%2520Titor /test.git" ) ;
379405 assertEquals (
380406 bufname ,
381407 {
382408 scheme : "denops" ,
383- expr : "/C:/Users/John Titor /test.git" ,
409+ expr : "/C:/Users/John%20Titor /test.git" ,
384410 } ,
385411 ) ;
386412 assertEquals (
387413 path . win32 . fromFileUrl ( `file://${ bufname . expr } ` ) ,
388414 "C:\\Users\\John Titor\\test.git" ,
389415 ) ;
390416} ) ;
417+ Deno . test ( "parse decode percent-encoded characters ('%') in 'expr'" , ( ) => {
418+ const src = "denops:///hello%25world" ;
419+ const dst = parse ( src ) ;
420+ const exp = {
421+ scheme : "denops" ,
422+ expr : "/hello%world" ,
423+ } ;
424+ assertEquals ( dst , exp ) ;
425+ } ) ;
426+ Deno . test ( "parse decode percent-encoded characters ('%') in 'params'" , ( ) => {
427+ const src = "denops:///absolute/path/to/worktree;foo=%25foo" ;
428+ const dst = parse ( src ) ;
429+ const exp = {
430+ scheme : "denops" ,
431+ expr : "/absolute/path/to/worktree" ,
432+ params : {
433+ foo : "%foo" ,
434+ } ,
435+ } ;
436+ assertEquals ( dst , exp ) ;
437+ } ) ;
438+ Deno . test ( "parse decode bufname that cause 'URI malformed' on denops-std v3.8.1" , ( ) => {
439+ const src =
440+ "ginlog:///Users/alisue/ghq/github.com/lambdalisue/gin.vim;pretty=%22%25C%28yellow%29%25h%25C%28reset%29+%25C%28magenta%29%5B%25ad%5D%25C%28reset%29%25C%28auto%29%25d%25C%28reset%29+%25s+%25C%28cyan%29%40%25an%25C%28reset%29%22#[]$" ;
441+ const dst = parse ( src ) ;
442+ const exp = {
443+ scheme : "ginlog" ,
444+ expr : "/Users/alisue/ghq/github.com/lambdalisue/gin.vim" ,
445+ params : {
446+ pretty :
447+ '"%C(yellow)%h%C(reset) %C(magenta)[%ad]%C(reset)%C(auto)%d%C(reset) %s %C(cyan)@%an%C(reset)"' ,
448+ } ,
449+ fragment : "[]$" ,
450+ } ;
451+ assertEquals ( dst , exp ) ;
452+ } ) ;
0 commit comments