brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.7k stars 2.31k forks source link

[Bug] Brave cannot open HTML files from folders with spaces in their name #35516

Open levicki opened 8 months ago

levicki commented 8 months ago

Description

Brave cannot open HTML files from folders whose names contain spaces.

Steps to Reproduce

  1. Create a folder in root of your drive, say C:\PATH WITH SPACES
  2. Create a blank file test.htm in said folder
  3. Double-click the file to launch it using Brave browser

Actual result:

Expected result:

Reproduces how often:

[Easily reproduced]

Brave version (brave://version info)

Brave 1.61.120 Chromium: 120.0.6099.234 (Official Build) (64-bit) Revision 362207c81bff0740a8b6cff62dd91c6789f5698f OS Windows 11 Version 23H2 (Build 22631.3007)

Version/Channel Information:

Other Additional Information:

Miscellaneous Information:

The cause of the issue is the (in my opinion incorrect) registration in windows registry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\BraveFile\shell\open\command]
@="\"C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe\" --single-argument %1"

The executable path itself is quoted, but the %1 argument isn't, so the browser will get --single argument C:\PATH instead of --single-argument "C:\PATH WITH SPACES\test.htm" and fail quite predictably to open the file.

One possible solution would be to use "%1" instead of %1.

EthanJamesBarron commented 8 months ago

HTML files in folders with spaces seem to work fine with me. Could it be something else?

levicki commented 8 months ago

HTML files in folders with spaces seem to work fine with me. Could it be something else?

Yes, it appears it could. Using another file manager (Total Commander) instead of Windows Explorer does it.

Windows Explorer seems to perform URLEncode on the path (` is replaced with%20`).

Still, I don't think it should be the responsibility of the file manager to escape or quote the string (it is most likely just calling ShellExecute anyway).

You can also try launching Brave from the command line.

This won't work:

"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" --single-argument C:\PATH WITH SPACES\test.htm

This will work:

"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" --single-argument "C:\PATH WITH SPACES\test.htm"

If you check how other apps are registering you will see most use quotes around %1 — here are a couple of examples:

Windows Registry Editor Version 5.00
; 7-Zip
[HKEY_CLASSES_ROOT\7-Zip.7z\shell\open\command]
@="\"C:\\Program Files\\7-Zip\\7zFM.exe\" \"%1\""
; Adobe Reader
[HKEY_CLASSES_ROOT\AcroExch.FDFDoc\shell\Open\command]
@="\"C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe\" \"%1\""
; Irfan View
[HKEY_CLASSES_ROOT\Applications\i_view64.exe\shell\open\command]
@="\"C:\\Program Files\\IrfanView\\i_view64.exe\" \"%1\""
; ImgBurn
[HKEY_CLASSES_ROOT\Applications\ImgBurn.exe\shell\open\command]
@="\"C:\\Program Files (x86)\\ImgBurn\\ImgBurn.exe\" /MODE WRITE /SOURCE \"%1\""
; Photoshop
[HKEY_CLASSES_ROOT\Applications\Photoshop.exe\shell\open\command]
@="\"C:\\Program Files\\Adobe\\Adobe Photoshop 2023\\Photoshop.exe\" \"%1\""
; Microsoft Word
[HKEY_CLASSES_ROOT\Applications\WINWORD.EXE\shell\edit\command]
@="\"C:\\Program Files\\Microsoft Office\\root\\Office16\\Winword.exe\" /n \"%1\""

TL;DR -- It is simple enough to add quotes to the %1 parameter in registry and be done with it instead of rellying on every possible file manager, shell replacement, terminal implementation, or application launcher to do the right thing.