Skip to content

Improve shellescape to handle apostrophes in paths#849

Merged
lervag merged 1 commit intolervag:masterfrom
danielwe:master
May 25, 2017
Merged

Improve shellescape to handle apostrophes in paths#849
lervag merged 1 commit intolervag:masterfrom
danielwe:master

Conversation

@danielwe
Copy link
Copy Markdown
Contributor

I was working in a directory tree on Ubuntu that happened to have an apostrophe somewhere in its path, i.e., /why/would/anyone's/folders/be/named/thus.tex. vimtex failed to open the resulting pdf, so I dug a little and found that after all the shellescapes and substitutions, the viewer call looked something like

xdg-open '/why/would/anyone'''s/folders/be/named/thus.pdf'

It seems like the bad things are happening on line 57 in autoload/vimtex/view/general.vim (and probably similar lines for the other viewers):

let l:cmd = substitute(l:cmd, '@pdf', vimtex#util#shellescape(outfile), 'g')

Actually, the output of vimtex#util#shellescape(outfile) looks OK, however the requisite escape character is removed by the outer call to substitute.

The solution I've implemented here is to explicitly escape the escape character in shellescape, like you're already doing on win32 systems. I haven't thought deeply about potential gotchas with this workaround, or done any tests except on this particular document, but since you're already doing this on Windows I figured it might not be too bad.

Btw., I've since repented and renamed my directories in a less pathological fashion, so I don't depend on this fix myself. But in case you'd like to support these edge cases, seeing as such paths are after all valid, here's a possible fix.

@lervag
Copy link
Copy Markdown
Owner

lervag commented May 24, 2017

Thanks! I'll have to check that this does not break something. If it won't break anything, then I don't see any reason not to accept this.

lervag added a commit that referenced this pull request May 25, 2017
@lervag
Copy link
Copy Markdown
Owner

lervag commented May 25, 2017

I could not find any problems with this, and so I see no reason not to merge it. Thanks!

@lervag lervag merged commit c0835fa into lervag:master May 25, 2017
@danielwe
Copy link
Copy Markdown
Contributor Author

My pleasure!

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

Successfully merging this pull request may close these issues.

2 participants