@@ -105,8 +105,6 @@ static void help(void)
105105 " OUTPUT\n"
106106 " -g, --get [{component}s] - output URL component(s)\n"
107107 " --json - output URL info as JSON\n"
108- " MODIFIERS\n"
109- " --urldecode - URL decode the output\n"
110108 " URL COMPONENTS:\n"
111109 " "
112110 );
@@ -134,7 +132,6 @@ struct option {
134132 const char * format ;
135133 FILE * url ;
136134 bool urlopen ;
137- bool urldecode ;
138135 bool jsonout ;
139136 unsigned char output ;
140137};
@@ -276,16 +273,14 @@ static int getarg(struct option *op,
276273 op -> format = arg ;
277274 * usedarg = 1 ;
278275 }
279- else if (!strcmp ("--urldecode" , flag ))
280- op -> urldecode = true;
281276 else if (!strcmp ("--json" , flag ))
282277 op -> jsonout = true;
283278 else
284279 return 1 ; /* unrecognized option */
285280 return 0 ;
286281}
287282
288- static void format (struct option * op , CURLU * uh )
283+ static void get (struct option * op , CURLU * uh )
289284{
290285 FILE * stream = stdout ;
291286 const char * ptr = op -> format ;
@@ -303,20 +298,26 @@ static void format(struct option *op, CURLU *uh)
303298 char * end ;
304299 size_t vlen ;
305300 int i ;
301+ bool urldecode = true;
306302 end = strchr (ptr , '}' );
307303 ptr ++ ; /* pass the { */
308304 if (!end ) {
309305 /* syntax error */
310306 continue ;
311307 }
308+ /* {path} {:path} */
309+ if (* ptr == ':' ) {
310+ urldecode = false;
311+ ptr ++ ;
312+ }
312313 vlen = end - ptr ;
313314 for (i = 0 ; variables [i ].name ; i ++ ) {
314315 if ((strlen (variables [i ].name ) == vlen ) &&
315316 !strncasecmp (ptr , variables [i ].name , vlen )) {
316317 char * nurl ;
317318 CURLUcode rc ;
318319 rc = curl_url_get (uh , variables [i ].part , & nurl , CURLU_DEFAULT_PORT |
319- (op -> urldecode ?CURLU_URLDECODE :0 ));
320+ (urldecode ?CURLU_URLDECODE :0 ));
320321 switch (rc ) {
321322 case CURLUE_OK :
322323 fprintf (stream , "%s" , nurl );
@@ -458,13 +459,13 @@ static void jsonString(FILE *stream, const char *in, bool lowercase)
458459static void json (struct option * o , CURLU * uh )
459460{
460461 int i ;
461-
462+ ( void ) o ;
462463 fputs ("{\n" , stdout );
463464 for (i = 0 ; variables [i ].name ; i ++ ) {
464465 char * nurl ;
465466 CURLUcode rc = curl_url_get (uh , variables [i ].part , & nurl ,
466467 (i ?CURLU_DEFAULT_PORT :0 )|
467- ( o -> urldecode ? CURLU_URLDECODE : 0 ) );
468+ CURLU_URLDECODE );
468469 if (!rc ) {
469470 printf (" \"%s\": " , variables [i ].name );
470471 jsonString (stdout , nurl , false);
@@ -543,13 +544,12 @@ static void singleurl(struct option *o,
543544 json (o , uh );
544545 else if (o -> format ) {
545546 /* custom output format */
546- format (o , uh );
547+ get (o , uh );
547548 }
548549 else {
549550 /* default output is full URL */
550551 char * nurl = NULL ;
551- if (!curl_url_get (uh , CURLUPART_URL , & nurl ,
552- o -> urldecode ?CURLU_URLDECODE :0 )) {
552+ if (!curl_url_get (uh , CURLUPART_URL , & nurl , 0 )) {
553553 printf ("%s\n" , nurl );
554554 curl_free (nurl );
555555 }
0 commit comments