Issue 4629: getopt should not accept no_argument that ends with '='
Created on 2008-12-11 06:54 by wangchun, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| getopt.py.diff | wangchun, 2008-12-11 07:12 | |||
| getopt-2.patch | vstinner, 2009-03-27 01:28 | |||
| Messages (7) | |||
|---|---|---|---|
| msg77597 - (view) | Author: Wang Chun (wangchun) | Date: 2008-12-11 06:54 | |
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$
|
|||
| msg78283 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2008-12-25 23:20 | |
Can you please also write a regression test in Lib/test/test_getopt.py? |
|||
| msg84247 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2009-03-27 01:28 | |
Updated patch with a regression test. |
|||
| msg84276 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2009-03-27 17:04 | |
The patch is good. |
|||
| msg108199 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2010-06-19 18:32 | |
I'm not sure why this is still open, would somebody like to comment, see also Issue4650. |
|||
| msg111394 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2010-07-23 21:55 | |
msg84276 "the patch is good". What is the problem with committing this? |
|||
| msg111406 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2010-07-24 01:13 | |
Fixed in 3.2 (r83116), 2.7 (r83117), 3.1 (r83118) and 2.6 (r83119). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:42 | admin | set | github: 48879 |
| 2010-07-24 01:13:18 | vstinner | set | status: open -> closed resolution: accepted -> fixed messages: + msg111406 |
| 2010-07-23 21:55:44 | BreamoreBoy | set | messages: + msg111394 |
| 2010-07-09 01:28:24 | BreamoreBoy | set | stage: commit review versions: + Python 3.2, - Python 2.6, Python 3.0 |
| 2010-06-19 18:32:48 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg108199 |
| 2009-03-27 17:04:10 | amaury.forgeotdarc | set | resolution: accepted messages:
+ msg84276 |
| 2009-03-27 01:28:56 | vstinner | set | files:
+ getopt-2.patch messages: + msg84247 |
| 2008-12-25 23:20:10 | vstinner | set | nosy:
+ vstinner messages: + msg78283 |
| 2008-12-20 14:28:46 | loewis | set | versions: - Python 2.5, Python 2.4, Python 2.3, Python 2.2.3, Python 2.2.2, Python 2.2.1, Python 2.2, Python 2.1.2, Python 2.1.1, Python 2.5.3 |
| 2008-12-11 07:12:45 | wangchun | set | files:
+ getopt.py.diff keywords: + patch |
| 2008-12-11 06:54:17 | wangchun | create | |
