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

[newbie] How to mend bug in this script?

Expand Messages
  • David
    Hello, under Ubuntu and Vim 7.2, the following cript (from http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line) has issues with
    Message 1 of 3 , Aug 4, 2009
    • 0 Attachment
      Hello,

      under Ubuntu and Vim 7.2, the following cript

      (from
      http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line)
      has issues with certain URLs. If I try to open, for example,
      http://www.vim.org/scripts/script.php?script_id=974, the script adds an
      extra \ between php and ?, yielding an error message from the server as
      it can't find the correct page.
      The trouble lies in this line:
      exec ':silent !firefox ' . "\"" . line . "\""

      If I converted {"\"" . line . "\""} into just
      { . line}
      the script works, but is no longer protected by quotes.

      I realize that there also is this line:
      let line = escape (line, "#?&;|%")
      But what damage would be created by taking the ? out?

      Could someone help me to figure out how to change the line so that the
      URL doesn't break while preserving the quotes' protection?

      Thanks!

      David


      "let $PATH = $PATH . ';c:\Programs\FireFox1.5'
      " Evoke a web browser
      function! Browser ()
      let line0 = getline (".")
      let line = matchstr (line0, "http[^ ]*")
      :if line==""
      let line = matchstr (line0, "ftp[^ ]*")
      :endif
      :if line==""
      let line = matchstr (line0, "file[^ ]*")
      :endif
      let line = escape (line, "#?&;|%")
      ":if line==""
      " let line = "\"" . (expand("%:p")) . "\""
      ":endif
      exec ':silent !firefox ' . "\"" . line . "\""
      endfunction
      map ,w :call Browser ()<CR>

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Andreas Johansson
      ... It seems to me that the escape line is unneccessary since the URL is protected by quoting it in the exec line. Either you escape special characters to
      Message 2 of 3 , Aug 4, 2009
      • 0 Attachment
        2009/8/4 David <ldl08@...>:
        >
        > Hello,
        >
        > under Ubuntu and Vim 7.2, the following cript
        >
        > (from
        > http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line)
        >  has issues with certain URLs. If I try to open, for example,
        > http://www.vim.org/scripts/script.php?script_id=974, the script adds an
        > extra \ between php and ?, yielding an error message from the server as
        > it can't find the correct page.
        > The trouble lies in this line:
        > exec ':silent !firefox ' . "\"" . line . "\""
        >
        > If I converted {"\"" . line . "\""} into just
        > { . line}
        > the script works, but is no longer protected by quotes.
        >
        > I realize that there also is this line:
        > let line = escape (line, "#?&;|%")
        > But what damage would be created by taking the ? out?
        >
        > Could someone help me to figure out how to change the line so that the
        > URL doesn't break while preserving the quotes' protection?
        >
        > Thanks!
        >
        > David

        It seems to me that the escape line is unneccessary since the URL is
        protected by quoting it in the exec line. Either you escape special
        characters to prevent the shell from parsing it, or you enclose the
        argument in quotes. If you enclose the URL in quotes, however, I guess
        you need to escape any quotes in the URL by changing the escape line
        to

        let line = escape(line, '"')

        // Andreas

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • David
        Hello! Swapping let line = escape (line, #?&;|% ) for let line = escape(line, ) seems to have done the trick! Thanks! David ...
        Message 3 of 3 , Aug 5, 2009
        • 0 Attachment
          Hello!

          Swapping

          let line = escape (line, "#?&;|%")
          for
          let line = escape(line, '"')

          seems to have done the trick! Thanks!

          David


          Andreas Johansson wrote:
          > 2009/8/4 David <ldl08@...>:
          >> Hello,
          >>
          >> under Ubuntu and Vim 7.2, the following cript
          >>
          >> (from
          >> http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line)
          >> has issues with certain URLs. If I try to open, for example,
          >> http://www.vim.org/scripts/script.php?script_id=974, the script adds an
          >> extra \ between php and ?, yielding an error message from the server as
          >> it can't find the correct page.
          >> The trouble lies in this line:
          >> exec ':silent !firefox ' . "\"" . line . "\""
          >>
          >> If I converted {"\"" . line . "\""} into just
          >> { . line}
          >> the script works, but is no longer protected by quotes.
          >>
          >> I realize that there also is this line:
          >> let line = escape (line, "#?&;|%")
          >> But what damage would be created by taking the ? out?
          >>
          >> Could someone help me to figure out how to change the line so that the
          >> URL doesn't break while preserving the quotes' protection?
          >>
          >> Thanks!
          >>
          >> David
          >
          > It seems to me that the escape line is unneccessary since the URL is
          > protected by quoting it in the exec line. Either you escape special
          > characters to prevent the shell from parsing it, or you enclose the
          > argument in quotes. If you enclose the URL in quotes, however, I guess
          > you need to escape any quotes in the URL by changing the escape line
          > to
          >
          > let line = escape(line, '"')
          >
          > // Andreas
          >
          > >


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.