mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-26 03:27:21 +08:00
Fix #3278 - Handle UTF-8 in URI encoding/decoding
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
" This probably doesn't handle Unicode characters well.
|
||||
function! s:EncodeChar(char) abort
|
||||
let l:result = ''
|
||||
|
||||
for l:index in range(strlen(a:char))
|
||||
let l:result .= printf('%%%02x', char2nr(a:char[l:index]))
|
||||
endfor
|
||||
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
function! ale#uri#Encode(value) abort
|
||||
return substitute(
|
||||
\ a:value,
|
||||
\ '\([^a-zA-Z0-9\\/$\-_.!*''(),]\)',
|
||||
\ '\=printf(''%%%02x'', char2nr(submatch(1)))',
|
||||
\ '\=s:EncodeChar(submatch(1))',
|
||||
\ 'g'
|
||||
\)
|
||||
endfunction
|
||||
@@ -12,7 +21,7 @@ function! ale#uri#Decode(value) abort
|
||||
return substitute(
|
||||
\ a:value,
|
||||
\ '%\(\x\x\)',
|
||||
\ '\=nr2char(''0x'' . submatch(1))',
|
||||
\ '\=printf("%c", str2nr(submatch(1), 16))',
|
||||
\ 'g'
|
||||
\)
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user