Loading ...
Sorry, an error occurred while loading the content.
 

BUG: Either fnameescape or shellescape should also escape "(" and ")", shoudn't it?

Expand Messages
  • lith
    Hi! Let s assume files is [ foo(bar).txt ]. Let s try ... This throws an error (on ubuntu 12.04). ... I think though this shouldn t be necessary since it
    Message 1 of 5 , Jul 5, 2014
      Hi!

      Let's assume files is ['foo(bar).txt']. Let's try

      :exec 'grep' fnameescape(join(files))

      This throws an error (on ubuntu 12.04).

      The following solves the problem:

      :exec 'grep' escape(fnameescape(join(files)), '()')

      I think though this shouldn't be necessary since it somehow undermines the usefulness of fnameescape(). IMHO fnameescape() should also escape '()', shoudn't it?

      Regards,
      Tom

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Bram Moolenaar
      ... fnameescape() is for Vim commands. Since grep executes an external command you need to use shellescape(). And that does handle parens. ... ls: cannot
      Message 2 of 5 , Jul 5, 2014
        Tom Lith wrote:

        > Let's assume files is ['foo(bar).txt']. Let's try
        >
        > :exec 'grep' fnameescape(join(files))
        >
        > This throws an error (on ubuntu 12.04).
        >
        > The following solves the problem:
        >
        > :exec 'grep' escape(fnameescape(join(files)), '()')
        >
        > I think though this shouldn't be necessary since it somehow undermines
        > the usefulness of fnameescape(). IMHO fnameescape() should also escape
        > '()', shoudn't it?

        fnameescape() is for Vim commands. Since "grep" executes an external
        command you need to use shellescape(). And that does handle parens.

        :exe '!ls ' . shellescape('asdf(asdf)asdf')
        ls: cannot access asdf(asdf)asdf: No such file or directory

        --
        Proofread carefully to see if you any words out.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • ZyX
        ... It is incorrect to use shellescape() for :! without the second argument: exe !ls shellescape( %%% ) will show you anything, but not “ls: cannot access
        Message 3 of 5 , Jul 5, 2014
          > fnameescape() is for Vim commands. Since "grep" executes an external
          > command you need to use shellescape(). And that does handle parens.
          >
          > :exe '!ls ' . shellescape('asdf(asdf)asdf')
          > ls: cannot access asdf(asdf)asdf: No such file or directory

          It is incorrect to use shellescape() for :! without the second argument:

          exe '!ls' shellescape('%%%')

          will show you anything, but not “ls: cannot access %%%: No such file or directory”.

          exe '!ls' shellescape('%%%', 1)

          is the correct variant.

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • ZyX
          ... Are you sure you have written exactly what you want? If you assume files is [ a , b ] and these files exist, ... will not work, neither will work correct
          Message 4 of 5 , Jul 5, 2014
            On Saturday, July 5, 2014 12:42:19 PM UTC+4, lith wrote:
            > Hi!
            >
            > Let's assume files is ['foo(bar).txt']. Let's try
            >
            > :exec 'grep' fnameescape(join(files))

            Are you sure you have written exactly what you want? If you assume files is ['a', 'b'] and these files exist,

            :execute 'grep' fnameescape(join(files))

            will not work, neither will work correct

            :execute 'grep' shellescape(join(files), 1)

            : both will try to use a single file named `a b`.

            You need

            :execute 'grep' join(map(files, 'shellescape(v:val, 1)'))

            >
            > This throws an error (on ubuntu 12.04).
            >
            > The following solves the problem:
            >
            > :exec 'grep' escape(fnameescape(join(files)), '()')
            >
            > I think though this shouldn't be necessary since it somehow undermines the usefulness of fnameescape(). IMHO fnameescape() should also escape '()', shoudn't it?

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • tom
            ... Thanks for pointing out the optional special argument to me. Regards, Tom -- -- You received this message from the vim_dev maillist. Do not top-post!
            Message 5 of 5 , Jul 6, 2014
              > You need :execute 'grep' join(map(files, 'shellescape(v:val, 1)'))
              Thanks for pointing out the optional "special" argument to me.

              Regards,
              Tom

              --
              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            Your message has been successfully submitted and would be delivered to recipients shortly.