Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: unconditional URL encode (encode all chars) #207

Closed
dkasak opened this issue Sep 20, 2020 · 8 comments
Closed

Feature request: unconditional URL encode (encode all chars) #207

dkasak opened this issue Sep 20, 2020 · 8 comments

Comments

@dkasak
Copy link

dkasak commented Sep 20, 2020

Currently, the URL encode feature ([u) only encodes characters which are reserved in a URL. However, I often want to percent-encode all characters.

Would you consider something like this? Seems like it would fit nicely on [U.

@dkasak
Copy link
Author

dkasak commented Sep 20, 2020

I forgot to mention my use case for this: it's very useful for pentesting and websec work, for instance when editing a URL or constructing payloads in an attempt to exploit and/or bypass a WAF.

@tpope
Copy link
Owner

tpope commented Sep 22, 2020

Unfortunately there's just not enough mappings to go around for all the numerous variants of the various encodings. For URL encoding, you could just as easily use [U for the query parameter variant that encodes spaces as + rather than %20, for example, or a variant that does the bare minimum like : and /, allowing insignificant punctuation and 8 bit characters through. I would consider both of those higher priority for a dedicated map than your more niche use case.

Fear not, though, as UnimpairedMapTransform is public, so you can create your own map in after/plugin/unimpaired.vim in just a few lines. The only catch is you need to use a public implementation function rather than a s: one.

@tpope tpope closed this as completed Sep 22, 2020
@dkasak
Copy link
Author

dkasak commented Sep 22, 2020

Fair enough!

Fear not, though, as UnimpairedMapTransform is public, so you can create your own map in after/plugin/unimpaired.vim in just a few lines. The only catch is you need to use a public implementation function rather than a s: one.

And thanks for this tip, this is indeed enough for me.

@dkasak
Copy link
Author

dkasak commented Sep 22, 2020

Actually, putting the following in after/plugin/unimpaired.vim doesn't seem to work (no mapping seems to be generated):

function! UrlEncodeAll(str) abort
  return substitute(iconv(a:str, 'latin1', 'utf-8'),'.','\="%".printf("%02X",char2nr(submatch(0)))','g')
endfunction

call UnimpairedMapTransform('UrlEncodeAll', '[U')

Did I miss something?

@tpope
Copy link
Owner

tpope commented Sep 22, 2020

Make sure it's in your runtimepath. ~/.vim/after/plugin/unimpaired.vim should work. Check :scriptnames and make sure it was loaded.

@dkasak
Copy link
Author

dkasak commented Sep 22, 2020

I checked, it is loaded. I also tried doing the UnimpairedMapTransform call manually after vim starts up. It reports no errors, but the result is the same.

Interestingly, the <Plug> mappings seem to be created correctly:

n  <Plug>unimpaired_line_UrlEncodeAll * <SNR>57_TransformSetup("UrlEncodeAll")."_"                                                                                                                                                             
x  <Plug>unimpaired_UrlEncodeAll * <SNR>57_TransformSetup("UrlEncodeAll")                                                                                                                                                                      
n  <Plug>unimpaired_UrlEncodeAll * <SNR>57_TransformSetup("UrlEncodeAll")                                                                                                                                                                      

Just the [U mappings are missing. Creating them by hand makes it work, so I guess that's a possible workaround, but I'm not sure what's going wrong.

@tpope
Copy link
Owner

tpope commented Sep 22, 2020

Goddammit it broke with d53b0bd. You'll have to provide the actual [U map yourself until I get around to fixing this, which won't be any time soon.

@dkasak
Copy link
Author

dkasak commented Sep 23, 2020

No worries, I'll just work around it for the time being.

Just in case anyone needs it, this is the full snippet to make it work:

function! UrlEncodeAll(str) abort
  return substitute(iconv(a:str, 'latin1', 'utf-8'),'.','\="%".printf("%02X",char2nr(submatch(0)))','g')
endfunction

call UnimpairedMapTransform('UrlEncodeAll', '[U')

nmap [U <Plug>unimpaired_UrlEncodeAll
xmap [U <Plug>unimpaired_UrlEncodeAll
nmap [UU <Plug>unimpaired_line_UrlEncodeAll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants