Forum Bugs

Protocol Relative URLs + baseurl that is protocol relative or protocol-less results in oddities

joelmeador
Given a stylesheet linked like:

<link rel="stylesheet" href="//d1030xxn62fyyb.cloudfront.net/assets/application-5c5c338a5fdfbb53174216d6a68a264a740f3b04ef761e980241c79faddc9e1f.css">


There is some weird behavior when passing in a baseurl that doesn't have a protocol. First, no protocol at all:

$ vendor/prince/versions/11.2/lib/prince/bin/prince --server -vvv --baseurl=docraptor.com --media=all --input=html ~/support/baseurl-test.html
msg|inf||loading document: vendor/prince/versions/11.2/lib/prince/license/license.dat
sta|Loading document...
msg|inf||loading HTML5 input: /Users/joel/support/baseurl-test.html
msg|inf||loading document: /Users/joel/support/baseurl-test.html
sta|Applying style sheets...
msg|inf||loading style sheet: /d1030xxn62fyyb.cloudfront.net/assets/application-5c5c338a5fdfbb53174216d6a68a264a740f3b04ef761e980241c79faddc9e1f.css
msg|wrn|/d1030xxn62fyyb.cloudfront.net/assets/application-5c5c338a5fdfbb53174216d6a68a264a740f3b04ef761e980241c79faddc9e1f.css|can't open input file: No such file or directory
sta|Preparing document...
sta|Converting document...
prg|0
msg|inf||used font: Times New Roman, Bold
msg|inf||used font: Times New Roman, Regular
prg|100
fin|success


The passing in a protocol relative url:

$ vendor/prince/versions/11.2/lib/prince/bin/prince --server -vvv --baseurl=//docraptor.com --media=all --input=html ~/support/baseurl-test.html
msg|inf||loading document: vendor/prince/versions/11.2/lib/prince/license/license.dat
sta|Loading document...
msg|inf||loading HTML5 input: /Users/joel/support/baseurl-test.html
msg|inf||loading document: /Users/joel/support/baseurl-test.html
sta|Applying style sheets...
msg|inf||loading style sheet: /d1030xxn62fyyb.cloudfront.net/assets/application-5c5c338a5fdfbb53174216d6a68a264a740f3b04ef761e980241c79faddc9e1f.css
msg|wrn|/d1030xxn62fyyb.cloudfront.net/assets/application-5c5c338a5fdfbb53174216d6a68a264a740f3b04ef761e980241c79faddc9e1f.css|can't open input file: No such file or directory
sta|Preparing document...
sta|Converting document...
prg|0
msg|inf||used font: Times New Roman, Bold
msg|inf||used font: Times New Roman, Regular
prg|100
fin|success


My expectation would be that protocol relative URLs would be left alone for the purposes of getting assets in documents, regardless of a baseurl. A customer reported a variant of this in which the protocol relative URLs inside their stylesheet were being mishandled.

An interesting side effect of this is that Prince can be forced to read files from anywhere on the FS with this, which is not great, but also probably not a huge concern for most users.
mikeday
The issue here is that a base URL of "docraptor.com" will be interpreted as a file path as it lacks a protocol like http:// or https://.
joelmeador
Yeah, but why would “//” be interpreted as part of a path when it's in a URL location?
mikeday
If the base URL is file://some/path and the link URL is protocol relative then it will resolve to another file: URL, not a HTTP or HTTPS URL.

For example if you have a local HTML file and include a link like this: <a href="//microsoft.com"> the browser will not treat this as a HTTP URL.
joelmeador
In your mentioned test case it would be looking for a file "/microsoft.com"? That is very weird, but I think I get it now. Thanks!