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

Bug (Windows): Launching through API fails with URLs containing single quote marks #62

Closed
schmich opened this issue Apr 15, 2013 · 6 comments
Milestone

Comments

@schmich
Copy link
Contributor

schmich commented Apr 15, 2013

My environment:

  • Windows 7 x64
  • Ruby 1.9.3p392
  • Launchy 2.2.0

Launchy fails when trying to open a URL containing any single quote (') characters. Example:

require 'launchy'
Launchy.open("http://google.com/?q=launchy's+great")

On my machine, this just opens a new command prompt and does not open any browser.

This works fine if I remove the single quote character or encode it as %27. Single quote characters are valid in URLs, though, so this should just work without needing to encode.

Launchy debug output:

LAUNCHY_DEBUG: Checking if class Launchy::Application::Browser is the one for handles?(http://google.com/?q=launchy's+great)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(mingw32)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::HostOsFamily::Windows is the one for matches?(mingw32)}
LAUNCHY_DEBUG: Checking if class Launchy::Detect::RubyEngine::Mri is the one for is_current_engine?(ruby)}
LAUNCHY_DEBUG: Launchy::Application::Browser : possibility : start /b
LAUNCHY_DEBUG: Launchy::Application::Browser : Using browser value 'start /b'
LAUNCHY_DEBUG: commandline_normalized => start /b http://google.com/?q=launchy's+great
LAUNCHY_DEBUG: Windows: all_args => ["cmd", "/c", "start", "/b", "http://google.com/?q=launchy's+great"]

If I manually run cmd /c start /b http://google.com/?q=launchy's+great from the command line, my default browser opens with the URL correctly.

Here's my guess as to what's happening:

  • I think the final system call to run the command is wrapping the URL in double quotes.
  • Therefore, the command becomes cmd /c start /b "http://google.com/?q=launchy's+great"
  • On Windows, start treats the first double-quoted argument as the window title (see start /?), so it doesn't think there's any specified command or program, which explains why a new command prompt is opened.
  • I think the final command should end up being cmd /c start /b "" "http://google.com/?q=launchy's+great" (note the empty quotes specifying the title argument).

I haven't had a chance to dig through the code much. If I get some time, I'll fork and fix this.

Thanks & regards,
Chris

@copiousfreetime
Copy link
Owner

if you change that to Launchy.open("http://google.com/?q=launchy's+great", :dry_run => true) then it should output the exact parameters that were sent to system(). My initial thought is that the system call itself is wrapping the parameter in quotes, as it I don't think Launchy is.

If you can do that along with the debug, that should add some additional help. I don't have a windows machine to do this testing on, so all my windows fixing is done by generous folks like yourself.

Does start have the same syntax in all versions of windows? Could the possibility exist that there are slight differences between windows versions that i'll need to check?

@copiousfreetime
Copy link
Owner

The other item to possibly check is the use of #shellsplit in https://github.com/copiousfreetime/launchy/blob/master/lib/launchy/detect/runner.rb#L85. If you change that to just #split does everything work just fine?

@schmich
Copy link
Contributor Author

schmich commented Apr 16, 2013

My initial thought is that the system call itself is wrapping the parameter in quotes, as it I don't think Launchy is.

You're right. Looking at the documentation for system, the call behaves differently depending on the arguments specified.

The array version used in Launchy in runner.rb allows the system call to manipulate the command-line arguments. Using Process Monitor, I verified that the URL argument was indeed quoted.

Ultimately, I think we just have to appease start's unfortunate command-line syntax. I think the right fix here is to always specify the command in the form of cmd /c start /b "" "http://google.com/?q=launchy's+great" since the URL argument might have spaces and might need to be quoted anyway.

I'll submit a fix when I get the chance and ensure that this is the right behavior for all supported versions of Windows.

@copiousfreetime
Copy link
Owner

Excellent, and don't forget to add yourself to CONTRIBUTING.md

@copiousfreetime
Copy link
Owner

Hi @schmich checking in to see if you ever created a patch for this issue.

@copiousfreetime
Copy link
Owner

version 2.4.0 released which I hope fixes this. If you can, please verify.

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