summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2020-08-10 02:03:41 +0100
committerw0rp <devw0rp@gmail.com>2020-08-10 02:03:41 +0100
commit05210846e41ea1e3cfc1c8e91834951f642348f7 (patch)
tree78909caa7ecd99e78528acdc43fb4ad64d579288 /autoload
parentbf3c3e943880876e2a8f3bf04c26f365c63fd0ad (diff)
downloadale-05210846e41ea1e3cfc1c8e91834951f642348f7.zip
Fix #3278 - Handle UTF-8 in URI encoding/decoding
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/uri.vim15
1 files changed, 12 insertions, 3 deletions
diff --git a/autoload/ale/uri.vim b/autoload/ale/uri.vim
index 934637d9..e71c6340 100644
--- a/autoload/ale/uri.vim
+++ b/autoload/ale/uri.vim
@@ -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