@@ -317,6 +317,7 @@ static void trurl_warnf(struct option *o, const char *fmt, ...)
317317struct string qpairs [MAX_QPAIRS ]; /* encoded */
318318struct string qpairsdec [MAX_QPAIRS ]; /* decoded */
319319int nqpairs ; /* how many is stored */
320+ bool query_is_modified = false;
320321
321322static void trurl_cleanup_options (struct option * o )
322323{
@@ -1081,6 +1082,7 @@ static void trim(struct option *o)
10811082 }
10821083 free (temp );
10831084 }
1085+ query_is_modified = true;
10841086 }
10851087}
10861088
@@ -1218,21 +1220,23 @@ static void extractqpairs(CURLU *uh, struct option *o)
12181220
12191221static void qpair2query (CURLU * uh , struct option * o )
12201222{
1221- int i ;
1222- char * nq = NULL ;
1223- for (i = 0 ; i < nqpairs ; i ++ ) {
1224- char * oldnq = nq ;
1225- nq = curl_maprintf ("%s%s%s" , nq ?nq :"" ,
1226- (nq && * nq && * (qpairs [i ].str ))? o -> qsep : "" ,
1227- qpairs [i ].str );
1228- curl_free (oldnq );
1229- }
1230- if (nq ) {
1231- int rc = curl_url_set (uh , CURLUPART_QUERY , nq , 0 );
1232- if (rc )
1233- trurl_warnf (o , "internal problem" );
1223+ if (query_is_modified ) {
1224+ int i ;
1225+ char * nq = NULL ;
1226+ for (i = 0 ; i < nqpairs ; i ++ ) {
1227+ char * oldnq = nq ;
1228+ nq = curl_maprintf ("%s%s%s" , nq ?nq :"" ,
1229+ (nq && * nq && * (qpairs [i ].str ))? o -> qsep : "" ,
1230+ qpairs [i ].str );
1231+ curl_free (oldnq );
1232+ }
1233+ if (nq ) {
1234+ int rc = curl_url_set (uh , CURLUPART_QUERY , nq , 0 );
1235+ if (rc )
1236+ trurl_warnf (o , "internal problem" );
1237+ }
1238+ curl_free (nq );
12341239 }
1235- curl_free (nq );
12361240}
12371241
12381242/* sort case insensitively */
@@ -1258,6 +1262,7 @@ static void sortquery(struct option *o)
12581262 /* not these two lists may no longer be the same order after the sort */
12591263 qsort (& qpairs [0 ], nqpairs , sizeof (struct string ), cmpfunc );
12601264 qsort (& qpairsdec [0 ], nqpairs , sizeof (struct string ), cmpfunc );
1265+ query_is_modified = true;
12611266 }
12621267}
12631268
@@ -1313,6 +1318,7 @@ static void replace(struct option *o)
13131318 key .str );
13141319 addqpair (key .str , strlen (key .str ), o -> jsonout );
13151320 }
1321+ query_is_modified = true;
13161322 }
13171323}
13181324static CURLUcode seturl (struct option * o , CURLU * uh , const char * url )
@@ -1470,6 +1476,7 @@ static void singleurl(struct option *o,
14701476 /* append query segments */
14711477 for (p = o -> append_query ; p ; p = p -> next ) {
14721478 addqpair (p -> data , strlen (p -> data ), o -> jsonout );
1479+ query_is_modified = true;
14731480 }
14741481
14751482 sortquery (o );
0 commit comments