Screengrabbing local file with query string doesn't work
dulnan opened this issue · 5 comments
I tried to run the script to take a screenshot of a local html file with a query string:
$ webkit2png /tmp/file.html?test=test
Fetching file://localhost/tmp/file.html%3Ftest=test ...
... something went wrong: The requested URL was not found on this server.
Okay, I was able to "fix" the problem (with a quick solution) by removing this if statement here on line 173.
initFileURLWithPath seems to encode the URL
if not (nsurl and nsurl.scheme()):
nsurl = Foundation.NSURL.alloc().initFileURLWithPath_(url)
As it stands the input is either a file or a url and the logic there is already slightly too confusing for my liking.
/tmp/file.html?test=test
is a mixture of the two cases (it starts as a filename and ends as a URL) and I don't think allowing mixtures like this makes sense. The biggest reason is that /tmp/file.html?test=test
is a valid filename:
$ echo foo > '/tmp/file.html?test=test'
$ cat /tmp/file.html\?test\=test
foo
$ webkit2png /tmp/file.html\?test\=test
Fetching file://localhost/tmp/file.html%3Ftest=test ...
... done
This might seem an edge case, but wget makes filenames exactly like this:
$ wget http://www.example.com/?foo
…
Saving to: ‘index.html?foo’
$ wc -l index.html\?foo
50 index.html?foo
So if I add logic to do something different with ? in filenames then webkit2png will no longer do the right thing with the output of a wget. The obvious way to handle this would be to find some way to specify whether you want the argument to be treated as a file or a url, but webkit2png already has that.
Which is a really really long way of saying that webkit2png file:///tmp/file.html?test=test
will already do what you want it to without changing the code. Does that work for you?
(Also, I'm assuming you're using the latest development version because none of this works at all in 0.6)
Sometimes the solution is that easy – of course it works when I put file:// before the path. Thanks!
Yay!
One extra note: if you have multiple query parameters (separated by &), make sure to escape these on the command line using a backslash () character:
webkit2png file:///tmp/file.html?test=test&second=more+tests