Closed Bug 1600413 Opened 5 years ago Closed 3 years ago

[macOS] Opening file URIs from the CLI strips hash/query information from the URL

Categories

(Core :: Widget: Cocoa, defect, P3)

70 Branch
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: theshadow, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0

Steps to reproduce:

Attempt to open a PDF on the local disk to a specific page.

open -a "Firefox" --args -url 'file:///path/to/file.pdf#page=10'
open -a "Firefox" --args -url 'file:///path/to/file.pdf?pageNumber=10'

Actual results:

The PDF is opened but the page information is stripped opening the PDF to the first page.

Expected results:

It should open the PDF to the correct page so that we can use hypermedia links from other tools.

Command correction:

open -a "Firefox" 'file:///path/to/file.pdf#page=10'
open -a "Firefox" 'file:///path/to/file.pdf?pageNumber=10'

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → PDF Viewer

The priority flag is not set for this bug.
:bdahl, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bdahl)
Flags: needinfo?(bdahl)
Priority: -- → P3
Severity: normal → S4
Status: UNCONFIRMED → NEW
Ever confirmed: true

This also happens with file uris and html pages. I'm moving components since it's not specific to the PDF viewer.

Severity: S4 → --
Component: PDF Viewer → File Handling
Priority: P3 → --

This works fine on Windows. I expect we're normalizing URLs through some apple API and it throws away the query/hash bit. Certainly by the time any frontend / commandline handling code sees it, those bits are gone, so fixing this is going to need to happen at an earlier point in time.

Component: File Handling → Widget: Cocoa
Product: Firefox → Core
Summary: Opening PDF's from the CLI strips page information from the URL → [macOS] Opening file URIs from the CLI strips hash/query information from the URL

Haik, I vaguely remember you working on sanitizing URLs a while back. Did this apply to launching Firefox from the command line as well, or was that unrelated?

Severity: -- → S3
Flags: needinfo?(haftandilian)
Priority: -- → P3

(In reply to Stephen A Pohl [:spohl] from comment #6)

Haik, I vaguely remember you working on sanitizing URLs a while back. Did this apply to launching Firefox from the command line as well, or was that unrelated?

Yes, for bug 1722758 (and follow up fix bug 1737854). NSURL is more strict about which characters must be encoded in each portion of the URL so we have to manually encode some characters before passing them to [NSURL URLWithString]. I don't know if that's happening here and can see Safari has the same behavior for the file:/// example I tested. I'll leave the needinfo while I look into this.

Using the --args option to the open command does continue to work. I think this bug is specifically about when --args is not used and the open command treats the argument as a URL. Per the open man page, "If the file is in the form of a URL, the file will be opened as a URL."

This is a bug with the macOS open(1) command in how it handles file URLs. Specifically, the macOS open command recognizes file:/// arguments as URLs (as described in the man page) but removes the URL fragment and query string components before passing them to the target application on the command line. One can check the arguments passed to Firefox and see the problem using the $ ps -ef command after Firefox has been launched. The problem is not specific to Firefox and occurs with Safari and Chrome too.

As a workaround, pass the URL to Firefox directly using the --args option to open. For example,

$ open -a Firefox --args 'file:///path/to/file.pdf#page=10'

I've reported this to Apple as Feedback Request FB9954398 "/usr/bin/open Command Drops URL Fragment (and other components) from file:/// URLs".

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → INVALID
Flags: needinfo?(haftandilian)
You need to log in before you can comment on or make changes to this bug.