Fossil SCM
Add the PT() and PDT() macros for extracting query parameters with leading and trailing whitespace removed. Use those macros to in the check-in edit page. Do not create branches or tags with empty names. Ticket [e613f452fada00].
Commit
655e78209bc8fd35c58596cc9490d0c5a1e5fc15
Parent
ed5c19cd435421d…
2 files changed
+19
-2
+8
-8
+19
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -55,12 +55,12 @@ | ||
| 55 | 55 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| 56 | 56 | ** does the same except "y" is returned in place of NULL if there is not match. |
| 57 | 57 | */ |
| 58 | 58 | #define P(x) cgi_parameter((x),0) |
| 59 | 59 | #define PD(x,y) cgi_parameter((x),(y)) |
| 60 | -#define QP(x) quotable_string(cgi_parameter((x),0)) | |
| 61 | -#define QPD(x,y) quotable_string(cgi_parameter((x),(y))) | |
| 60 | +#define PT(x) cgi_parameter_trimmed((x),0) | |
| 61 | +#define PDT(x,y) cgi_parameter_trimmed((x),(y)) | |
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | /* |
| 65 | 65 | ** Destinations for output text. |
| 66 | 66 | */ |
| @@ -787,10 +787,27 @@ | ||
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | CGIDEBUG(("no-match [%s]\n", zName)); |
| 790 | 790 | return zDefault; |
| 791 | 791 | } |
| 792 | + | |
| 793 | +/* | |
| 794 | +** Return the value of a CGI parameter with leading and trailing | |
| 795 | +** spaces removed. | |
| 796 | +*/ | |
| 797 | +char *cgi_parameter_trimmed(const char *zName, const char *zDefault){ | |
| 798 | + const char *zIn; | |
| 799 | + char *zOut; | |
| 800 | + int i; | |
| 801 | + zIn = cgi_parameter(zName, 0); | |
| 802 | + if( zIn==0 ) zIn = zDefault; | |
| 803 | + while( fossil_isspace(zIn[0]) ) zIn++; | |
| 804 | + zOut = fossil_strdup(zIn); | |
| 805 | + for(i=0; zOut[i]; i++){} | |
| 806 | + while( i>0 && fossil_isspace(zOut[i-1]) ) zOut[--i] = 0; | |
| 807 | + return zOut; | |
| 808 | +} | |
| 792 | 809 | |
| 793 | 810 | /* |
| 794 | 811 | ** Return the name of the i-th CGI parameter. Return NULL if there |
| 795 | 812 | ** are fewer than i registered CGI parmaeters. |
| 796 | 813 | */ |
| 797 | 814 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -55,12 +55,12 @@ | |
| 55 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| 56 | ** does the same except "y" is returned in place of NULL if there is not match. |
| 57 | */ |
| 58 | #define P(x) cgi_parameter((x),0) |
| 59 | #define PD(x,y) cgi_parameter((x),(y)) |
| 60 | #define QP(x) quotable_string(cgi_parameter((x),0)) |
| 61 | #define QPD(x,y) quotable_string(cgi_parameter((x),(y))) |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | ** Destinations for output text. |
| 66 | */ |
| @@ -787,10 +787,27 @@ | |
| 787 | } |
| 788 | } |
| 789 | CGIDEBUG(("no-match [%s]\n", zName)); |
| 790 | return zDefault; |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | ** Return the name of the i-th CGI parameter. Return NULL if there |
| 795 | ** are fewer than i registered CGI parmaeters. |
| 796 | */ |
| 797 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -55,12 +55,12 @@ | |
| 55 | ** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y") |
| 56 | ** does the same except "y" is returned in place of NULL if there is not match. |
| 57 | */ |
| 58 | #define P(x) cgi_parameter((x),0) |
| 59 | #define PD(x,y) cgi_parameter((x),(y)) |
| 60 | #define PT(x) cgi_parameter_trimmed((x),0) |
| 61 | #define PDT(x,y) cgi_parameter_trimmed((x),(y)) |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | ** Destinations for output text. |
| 66 | */ |
| @@ -787,10 +787,27 @@ | |
| 787 | } |
| 788 | } |
| 789 | CGIDEBUG(("no-match [%s]\n", zName)); |
| 790 | return zDefault; |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | ** Return the value of a CGI parameter with leading and trailing |
| 795 | ** spaces removed. |
| 796 | */ |
| 797 | char *cgi_parameter_trimmed(const char *zName, const char *zDefault){ |
| 798 | const char *zIn; |
| 799 | char *zOut; |
| 800 | int i; |
| 801 | zIn = cgi_parameter(zName, 0); |
| 802 | if( zIn==0 ) zIn = zDefault; |
| 803 | while( fossil_isspace(zIn[0]) ) zIn++; |
| 804 | zOut = fossil_strdup(zIn); |
| 805 | for(i=0; zOut[i]; i++){} |
| 806 | while( i>0 && fossil_isspace(zOut[i-1]) ) zOut[--i] = 0; |
| 807 | return zOut; |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | ** Return the name of the i-th CGI parameter. Return NULL if there |
| 812 | ** are fewer than i registered CGI parmaeters. |
| 813 | */ |
| 814 |
+8
-8
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1579,29 +1579,29 @@ | ||
| 1579 | 1579 | } |
| 1580 | 1580 | zNewComment = PD("c",zComment); |
| 1581 | 1581 | zUser = db_text(0, "SELECT coalesce(euser,user)" |
| 1582 | 1582 | " FROM event WHERE objid=%d", rid); |
| 1583 | 1583 | if( zUser==0 ) fossil_redirect_home(); |
| 1584 | - zNewUser = PD("u",zUser); | |
| 1584 | + zNewUser = PDT("u",zUser); | |
| 1585 | 1585 | zDate = db_text(0, "SELECT datetime(mtime)" |
| 1586 | 1586 | " FROM event WHERE objid=%d", rid); |
| 1587 | 1587 | if( zDate==0 ) fossil_redirect_home(); |
| 1588 | - zNewDate = PD("dt",zDate); | |
| 1588 | + zNewDate = PDT("dt",zDate); | |
| 1589 | 1589 | zColor = db_text("", "SELECT bgcolor" |
| 1590 | 1590 | " FROM event WHERE objid=%d", rid); |
| 1591 | - zNewColor = PD("clr",zColor); | |
| 1591 | + zNewColor = PDT("clr",zColor); | |
| 1592 | 1592 | if( fossil_strcmp(zNewColor,"##")==0 ){ |
| 1593 | - zNewColor = P("clrcust"); | |
| 1593 | + zNewColor = PT("clrcust"); | |
| 1594 | 1594 | } |
| 1595 | 1595 | fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref" |
| 1596 | 1596 | " WHERE rid=%d AND tagid=%d", |
| 1597 | 1597 | rid, TAG_BGCOLOR)==2; |
| 1598 | 1598 | fNewPropagateColor = P("clr")!=0 ? P("pclr")!=0 : fPropagateColor; |
| 1599 | 1599 | zNewTagFlag = P("newtag") ? " checked" : ""; |
| 1600 | - zNewTag = PD("tagname",""); | |
| 1600 | + zNewTag = PDT("tagname",""); | |
| 1601 | 1601 | zNewBrFlag = P("newbr") ? " checked" : ""; |
| 1602 | - zNewBranch = PD("brname",""); | |
| 1602 | + zNewBranch = PDT("brname",""); | |
| 1603 | 1603 | zCloseFlag = P("close") ? " checked" : ""; |
| 1604 | 1604 | if( P("apply") ){ |
| 1605 | 1605 | Blob ctrl; |
| 1606 | 1606 | char *zNow; |
| 1607 | 1607 | int nChng = 0; |
| @@ -1651,14 +1651,14 @@ | ||
| 1651 | 1651 | } |
| 1652 | 1652 | db_finalize(&q); |
| 1653 | 1653 | if( zCloseFlag[0] ){ |
| 1654 | 1654 | db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)"); |
| 1655 | 1655 | } |
| 1656 | - if( zNewTagFlag[0] ){ | |
| 1656 | + if( zNewTagFlag[0] && zNewTag[0] ){ | |
| 1657 | 1657 | db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag); |
| 1658 | 1658 | } |
| 1659 | - if( zNewBrFlag[0] ){ | |
| 1659 | + if( zNewBrFlag[0] && zNewBranch[0] ){ | |
| 1660 | 1660 | db_multi_exec( |
| 1661 | 1661 | "REPLACE INTO newtags " |
| 1662 | 1662 | " SELECT tagname, '-', NULL FROM tagxref, tag" |
| 1663 | 1663 | " WHERE tagxref.rid=%d AND tagtype==2" |
| 1664 | 1664 | " AND tagname GLOB 'sym-*'" |
| 1665 | 1665 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1579,29 +1579,29 @@ | |
| 1579 | } |
| 1580 | zNewComment = PD("c",zComment); |
| 1581 | zUser = db_text(0, "SELECT coalesce(euser,user)" |
| 1582 | " FROM event WHERE objid=%d", rid); |
| 1583 | if( zUser==0 ) fossil_redirect_home(); |
| 1584 | zNewUser = PD("u",zUser); |
| 1585 | zDate = db_text(0, "SELECT datetime(mtime)" |
| 1586 | " FROM event WHERE objid=%d", rid); |
| 1587 | if( zDate==0 ) fossil_redirect_home(); |
| 1588 | zNewDate = PD("dt",zDate); |
| 1589 | zColor = db_text("", "SELECT bgcolor" |
| 1590 | " FROM event WHERE objid=%d", rid); |
| 1591 | zNewColor = PD("clr",zColor); |
| 1592 | if( fossil_strcmp(zNewColor,"##")==0 ){ |
| 1593 | zNewColor = P("clrcust"); |
| 1594 | } |
| 1595 | fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref" |
| 1596 | " WHERE rid=%d AND tagid=%d", |
| 1597 | rid, TAG_BGCOLOR)==2; |
| 1598 | fNewPropagateColor = P("clr")!=0 ? P("pclr")!=0 : fPropagateColor; |
| 1599 | zNewTagFlag = P("newtag") ? " checked" : ""; |
| 1600 | zNewTag = PD("tagname",""); |
| 1601 | zNewBrFlag = P("newbr") ? " checked" : ""; |
| 1602 | zNewBranch = PD("brname",""); |
| 1603 | zCloseFlag = P("close") ? " checked" : ""; |
| 1604 | if( P("apply") ){ |
| 1605 | Blob ctrl; |
| 1606 | char *zNow; |
| 1607 | int nChng = 0; |
| @@ -1651,14 +1651,14 @@ | |
| 1651 | } |
| 1652 | db_finalize(&q); |
| 1653 | if( zCloseFlag[0] ){ |
| 1654 | db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)"); |
| 1655 | } |
| 1656 | if( zNewTagFlag[0] ){ |
| 1657 | db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag); |
| 1658 | } |
| 1659 | if( zNewBrFlag[0] ){ |
| 1660 | db_multi_exec( |
| 1661 | "REPLACE INTO newtags " |
| 1662 | " SELECT tagname, '-', NULL FROM tagxref, tag" |
| 1663 | " WHERE tagxref.rid=%d AND tagtype==2" |
| 1664 | " AND tagname GLOB 'sym-*'" |
| 1665 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1579,29 +1579,29 @@ | |
| 1579 | } |
| 1580 | zNewComment = PD("c",zComment); |
| 1581 | zUser = db_text(0, "SELECT coalesce(euser,user)" |
| 1582 | " FROM event WHERE objid=%d", rid); |
| 1583 | if( zUser==0 ) fossil_redirect_home(); |
| 1584 | zNewUser = PDT("u",zUser); |
| 1585 | zDate = db_text(0, "SELECT datetime(mtime)" |
| 1586 | " FROM event WHERE objid=%d", rid); |
| 1587 | if( zDate==0 ) fossil_redirect_home(); |
| 1588 | zNewDate = PDT("dt",zDate); |
| 1589 | zColor = db_text("", "SELECT bgcolor" |
| 1590 | " FROM event WHERE objid=%d", rid); |
| 1591 | zNewColor = PDT("clr",zColor); |
| 1592 | if( fossil_strcmp(zNewColor,"##")==0 ){ |
| 1593 | zNewColor = PT("clrcust"); |
| 1594 | } |
| 1595 | fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref" |
| 1596 | " WHERE rid=%d AND tagid=%d", |
| 1597 | rid, TAG_BGCOLOR)==2; |
| 1598 | fNewPropagateColor = P("clr")!=0 ? P("pclr")!=0 : fPropagateColor; |
| 1599 | zNewTagFlag = P("newtag") ? " checked" : ""; |
| 1600 | zNewTag = PDT("tagname",""); |
| 1601 | zNewBrFlag = P("newbr") ? " checked" : ""; |
| 1602 | zNewBranch = PDT("brname",""); |
| 1603 | zCloseFlag = P("close") ? " checked" : ""; |
| 1604 | if( P("apply") ){ |
| 1605 | Blob ctrl; |
| 1606 | char *zNow; |
| 1607 | int nChng = 0; |
| @@ -1651,14 +1651,14 @@ | |
| 1651 | } |
| 1652 | db_finalize(&q); |
| 1653 | if( zCloseFlag[0] ){ |
| 1654 | db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)"); |
| 1655 | } |
| 1656 | if( zNewTagFlag[0] && zNewTag[0] ){ |
| 1657 | db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag); |
| 1658 | } |
| 1659 | if( zNewBrFlag[0] && zNewBranch[0] ){ |
| 1660 | db_multi_exec( |
| 1661 | "REPLACE INTO newtags " |
| 1662 | " SELECT tagname, '-', NULL FROM tagxref, tag" |
| 1663 | " WHERE tagxref.rid=%d AND tagtype==2" |
| 1664 | " AND tagname GLOB 'sym-*'" |
| 1665 |