Fossil SCM
Add robustness to the handling of command-line options in the "diff" and "test-diff" commands.
Commit
60d5b1f5a2c704a01412bb6fe3a0437498612b51
Parent
84dc7b0f3f1bd50…
2 files changed
+2
-1
+7
-1
+2
-1
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -1957,20 +1957,21 @@ | ||
| 1957 | 1957 | ** |
| 1958 | 1958 | ** Usage: %fossil [options] FILE1 FILE2 |
| 1959 | 1959 | ** |
| 1960 | 1960 | ** Print the difference between two files. The usual diff options apply. |
| 1961 | 1961 | */ |
| 1962 | -void test_udiff_cmd(void){ | |
| 1962 | +void test_diff_cmd(void){ | |
| 1963 | 1963 | Blob a, b, out; |
| 1964 | 1964 | u64 diffFlag; |
| 1965 | 1965 | |
| 1966 | 1966 | if( find_option("tk",0,0)!=0 ){ |
| 1967 | 1967 | diff_tk("test-diff", 2); |
| 1968 | 1968 | return; |
| 1969 | 1969 | } |
| 1970 | 1970 | find_option("i",0,0); |
| 1971 | 1971 | diffFlag = diff_options(); |
| 1972 | + verify_all_options(); | |
| 1972 | 1973 | if( g.argc!=4 ) usage("FILE1 FILE2"); |
| 1973 | 1974 | diff_print_filenames(g.argv[2], g.argv[3], diffFlag); |
| 1974 | 1975 | blob_read_from_file(&a, g.argv[2]); |
| 1975 | 1976 | blob_read_from_file(&b, g.argv[3]); |
| 1976 | 1977 | blob_zero(&out); |
| 1977 | 1978 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -1957,20 +1957,21 @@ | |
| 1957 | ** |
| 1958 | ** Usage: %fossil [options] FILE1 FILE2 |
| 1959 | ** |
| 1960 | ** Print the difference between two files. The usual diff options apply. |
| 1961 | */ |
| 1962 | void test_udiff_cmd(void){ |
| 1963 | Blob a, b, out; |
| 1964 | u64 diffFlag; |
| 1965 | |
| 1966 | if( find_option("tk",0,0)!=0 ){ |
| 1967 | diff_tk("test-diff", 2); |
| 1968 | return; |
| 1969 | } |
| 1970 | find_option("i",0,0); |
| 1971 | diffFlag = diff_options(); |
| 1972 | if( g.argc!=4 ) usage("FILE1 FILE2"); |
| 1973 | diff_print_filenames(g.argv[2], g.argv[3], diffFlag); |
| 1974 | blob_read_from_file(&a, g.argv[2]); |
| 1975 | blob_read_from_file(&b, g.argv[3]); |
| 1976 | blob_zero(&out); |
| 1977 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -1957,20 +1957,21 @@ | |
| 1957 | ** |
| 1958 | ** Usage: %fossil [options] FILE1 FILE2 |
| 1959 | ** |
| 1960 | ** Print the difference between two files. The usual diff options apply. |
| 1961 | */ |
| 1962 | void test_diff_cmd(void){ |
| 1963 | Blob a, b, out; |
| 1964 | u64 diffFlag; |
| 1965 | |
| 1966 | if( find_option("tk",0,0)!=0 ){ |
| 1967 | diff_tk("test-diff", 2); |
| 1968 | return; |
| 1969 | } |
| 1970 | find_option("i",0,0); |
| 1971 | diffFlag = diff_options(); |
| 1972 | verify_all_options(); |
| 1973 | if( g.argc!=4 ) usage("FILE1 FILE2"); |
| 1974 | diff_print_filenames(g.argv[2], g.argv[3], diffFlag); |
| 1975 | blob_read_from_file(&a, g.argv[2]); |
| 1976 | blob_read_from_file(&b, g.argv[3]); |
| 1977 | blob_zero(&out); |
| 1978 |
+7
-1
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -659,12 +659,18 @@ | ||
| 659 | 659 | char *zCmd; |
| 660 | 660 | blob_zero(&script); |
| 661 | 661 | blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i", |
| 662 | 662 | g.nameOfExe, zSubCmd); |
| 663 | 663 | for(i=firstArg; i<g.argc; i++){ |
| 664 | + const char *z = g.argv[i]; | |
| 665 | + if( z[0]=='-' ){ | |
| 666 | + if( strglob("*-html",z) ) continue; | |
| 667 | + if( strglob("*-y",z) ) continue; | |
| 668 | + if( strglob("*-i",z) ) continue; | |
| 669 | + } | |
| 664 | 670 | blob_append(&script, " ", 1); |
| 665 | - shell_escape(&script, g.argv[i]); | |
| 671 | + shell_escape(&script, z); | |
| 666 | 672 | } |
| 667 | 673 | blob_appendf(&script, "}\n%s", zDiffScript); |
| 668 | 674 | zTempFile = write_blob_to_temp_file(&script); |
| 669 | 675 | zCmd = mprintf("tclsh \"%s\"", zTempFile); |
| 670 | 676 | fossil_system(zCmd); |
| 671 | 677 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -659,12 +659,18 @@ | |
| 659 | char *zCmd; |
| 660 | blob_zero(&script); |
| 661 | blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i", |
| 662 | g.nameOfExe, zSubCmd); |
| 663 | for(i=firstArg; i<g.argc; i++){ |
| 664 | blob_append(&script, " ", 1); |
| 665 | shell_escape(&script, g.argv[i]); |
| 666 | } |
| 667 | blob_appendf(&script, "}\n%s", zDiffScript); |
| 668 | zTempFile = write_blob_to_temp_file(&script); |
| 669 | zCmd = mprintf("tclsh \"%s\"", zTempFile); |
| 670 | fossil_system(zCmd); |
| 671 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -659,12 +659,18 @@ | |
| 659 | char *zCmd; |
| 660 | blob_zero(&script); |
| 661 | blob_appendf(&script, "set cmd {| \"%/\" %s --html -y -i", |
| 662 | g.nameOfExe, zSubCmd); |
| 663 | for(i=firstArg; i<g.argc; i++){ |
| 664 | const char *z = g.argv[i]; |
| 665 | if( z[0]=='-' ){ |
| 666 | if( strglob("*-html",z) ) continue; |
| 667 | if( strglob("*-y",z) ) continue; |
| 668 | if( strglob("*-i",z) ) continue; |
| 669 | } |
| 670 | blob_append(&script, " ", 1); |
| 671 | shell_escape(&script, z); |
| 672 | } |
| 673 | blob_appendf(&script, "}\n%s", zDiffScript); |
| 674 | zTempFile = write_blob_to_temp_file(&script); |
| 675 | zCmd = mprintf("tclsh \"%s\"", zTempFile); |
| 676 | fossil_system(zCmd); |
| 677 |