neverpanic / google-font-download

Locally host Google's web fonts
https://neverpanic.de/blog/2014/03/19/downloading-google-web-fonts-for-local-hosting/
BSD 2-Clause "Simplified" License
706 stars 72 forks source link

Quote fonts with space in the name twice #1

Closed joelpurra closed 9 years ago

joelpurra commented 9 years ago

I order to download a font with a space in the name, I had to quote the name with both double and single quotes.

# Works as expected.
google-font-download "'Open Sans'"

This is in contrast with the docs which use Open Sans as an example, and only one set of quotes. Looking at the command output, it looks like the space will be parsed as two fonts, Open and Sans.

# Doesn't work as expected.
google-font-download "Open Sans"
neverpanic commented 9 years ago

This doesn't happen for me:

$ ../google-font-download "'Open Sans'"
Downloading 'Open Sans'... error: curl: (22) The requested URL returned error: 400 Bad Request
$ echo $?
1

I only need to quote once:

$ ../google-font-download "Open Sans"
Downloading Open Sans...eot woff svg ttf
$ echo $?
0

Consequently, this must somehow depend on your system. My guess would be your version of getopt. What does

getopt -T; echo $?

return on your system?

joelpurra commented 9 years ago

Assumed it had something to do with getopt, but it was also clear it works for you =)

getopt -T; echo $?
 --
0

Using Mac, so guess there's an incompatibility. I could brew install gnu-getopt, but not keen on putting it in my $PATH.

sw_vers
sw_vers
ProductName:    Mac OS X
ProductVersion: 10.10.3
BuildVersion:   14D136
neverpanic commented 9 years ago

Yeah, that's what I expected. OS X ships with a version of getopt that doesn't get these things right. The manpage of GNU getopt is pretty clear on this:

Traditional implementations of getopt(1) are unable to cope with whitespace and other (shell-specific) special characters in arguments and non-option parameters. To solve this problem, this implementation can generate quoted output which must once again be interpreted by the shell (usually by using the eval command). This has the effect of preserving those characters, but you must call getopt in a way that is no longer compatible with other versions (the second or third format in the SYNOPSIS). To determine whether this enhanced ver sion of getopt(1) is installed, a special test option (-T) can be used.

The least I can do is add the check and warn that double quoting will be necessary for fonts with whitespace or other special characters.

joelpurra commented 9 years ago

@neverpanic: documentation and a warning is good enough for me, as it wasn't too hard to figure out a solution to the problem to start with either. Thanks!

joelpurra commented 9 years ago

@neverpanic: v1.2.1 looks good to me! The terminal output looks better too. Thanks! =)