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].

drh 2011-04-18 12:29 trunk
Commit 655e78209bc8fd35c58596cc9490d0c5a1e5fc15
2 files changed +19 -2 +8 -8
+19 -2
--- src/cgi.c
+++ src/cgi.c
@@ -55,12 +55,12 @@
5555
** or cookie "x", or NULL if there is no such parameter or cookie. PD("x","y")
5656
** does the same except "y" is returned in place of NULL if there is not match.
5757
*/
5858
#define P(x) cgi_parameter((x),0)
5959
#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))
6262
6363
6464
/*
6565
** Destinations for output text.
6666
*/
@@ -787,10 +787,27 @@
787787
}
788788
}
789789
CGIDEBUG(("no-match [%s]\n", zName));
790790
return zDefault;
791791
}
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
+}
792809
793810
/*
794811
** Return the name of the i-th CGI parameter. Return NULL if there
795812
** are fewer than i registered CGI parmaeters.
796813
*/
797814
--- 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 @@
15791579
}
15801580
zNewComment = PD("c",zComment);
15811581
zUser = db_text(0, "SELECT coalesce(euser,user)"
15821582
" FROM event WHERE objid=%d", rid);
15831583
if( zUser==0 ) fossil_redirect_home();
1584
- zNewUser = PD("u",zUser);
1584
+ zNewUser = PDT("u",zUser);
15851585
zDate = db_text(0, "SELECT datetime(mtime)"
15861586
" FROM event WHERE objid=%d", rid);
15871587
if( zDate==0 ) fossil_redirect_home();
1588
- zNewDate = PD("dt",zDate);
1588
+ zNewDate = PDT("dt",zDate);
15891589
zColor = db_text("", "SELECT bgcolor"
15901590
" FROM event WHERE objid=%d", rid);
1591
- zNewColor = PD("clr",zColor);
1591
+ zNewColor = PDT("clr",zColor);
15921592
if( fossil_strcmp(zNewColor,"##")==0 ){
1593
- zNewColor = P("clrcust");
1593
+ zNewColor = PT("clrcust");
15941594
}
15951595
fPropagateColor = db_int(0, "SELECT tagtype FROM tagxref"
15961596
" WHERE rid=%d AND tagid=%d",
15971597
rid, TAG_BGCOLOR)==2;
15981598
fNewPropagateColor = P("clr")!=0 ? P("pclr")!=0 : fPropagateColor;
15991599
zNewTagFlag = P("newtag") ? " checked" : "";
1600
- zNewTag = PD("tagname","");
1600
+ zNewTag = PDT("tagname","");
16011601
zNewBrFlag = P("newbr") ? " checked" : "";
1602
- zNewBranch = PD("brname","");
1602
+ zNewBranch = PDT("brname","");
16031603
zCloseFlag = P("close") ? " checked" : "";
16041604
if( P("apply") ){
16051605
Blob ctrl;
16061606
char *zNow;
16071607
int nChng = 0;
@@ -1651,14 +1651,14 @@
16511651
}
16521652
db_finalize(&q);
16531653
if( zCloseFlag[0] ){
16541654
db_multi_exec("REPLACE INTO newtags VALUES('closed','+',NULL)");
16551655
}
1656
- if( zNewTagFlag[0] ){
1656
+ if( zNewTagFlag[0] && zNewTag[0] ){
16571657
db_multi_exec("REPLACE INTO newtags VALUES('sym-%q','+',NULL)", zNewTag);
16581658
}
1659
- if( zNewBrFlag[0] ){
1659
+ if( zNewBrFlag[0] && zNewBranch[0] ){
16601660
db_multi_exec(
16611661
"REPLACE INTO newtags "
16621662
" SELECT tagname, '-', NULL FROM tagxref, tag"
16631663
" WHERE tagxref.rid=%d AND tagtype==2"
16641664
" AND tagname GLOB 'sym-*'"
16651665
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button