Issue 4629: getopt should not accept no_argument that ends with '=' (original) (raw)
Consider the following program tmp.py:
import sys, getopt print(getopt.getopt(sys.argv[1:], '', ['help']))
The program accept "--help" without a value:
python helloworld.py --help
But if someone invoke the program like:
python helloworld.py --help=
Python should raise an error.
"--help=" is not considered as no_argument in libc's getopt implementation (tested on Mac OS X Leopard):
#include <getopt.h>
static struct option longopts[] = { { "help", no_argument, NULL, "h" }, };
#include <getopt.h>
static struct option longopts[] = { { "help", no_argument, NULL, 'h' }, };
int main(int argc, char **argv) { while (getopt_long(argc, argv, "h", longopts, NULL) != -1); return 0; }
macbook:/tmp$ gcc -o tmp tmp.c
macbook:/tmp$ ./tmp --help=
tmp: option `--help' doesn't allow an argument
macbook:~/tmp$