Skip to content

Commit d15647d

Browse files
committed
support conditionally set scheme
- requires libcurl 8.9.0: the feature is called "no-guess-scheme" - -v now lists all features in alphabetical order Added test cases for setting scheme conditionally Fixes #296 Closes #314
1 parent 21fff73 commit d15647d

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

tests.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,5 +2572,34 @@
25722572
"returncode": 10,
25732573
"stdout": ""
25742574
}
2575+
},
2576+
{
2577+
"required": ["no-guess-scheme"],
2578+
"input": {
2579+
"arguments": [
2580+
"example.com",
2581+
"--set",
2582+
"scheme?=https"
2583+
]
2584+
},
2585+
"expected": {
2586+
"stdout": "https://example.com/\n",
2587+
"stderr": "",
2588+
"returncode": 0
2589+
}
2590+
},
2591+
{
2592+
"input": {
2593+
"arguments": [
2594+
"ftp://example.com",
2595+
"--set",
2596+
"scheme?=https"
2597+
]
2598+
},
2599+
"expected": {
2600+
"stdout": "ftp://example.com/\n",
2601+
"stderr": "",
2602+
"returncode": 0
2603+
}
25752604
}
25762605
]

trurl.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ typedef enum {
7272
#if CURL_AT_LEAST_VERSION(7,30,0)
7373
#define SUPPORTS_IMAP_OPTIONS
7474
#endif
75+
#if CURL_AT_LEAST_VERSION(8,9,0)
76+
#define SUPPORTS_NO_GUESS_SCHEME
77+
#else
78+
#define CURLU_NO_GUESS_SCHEME 0
79+
#endif
7580

7681
#define OUTPUT_URL 0 /* default */
7782
#define OUTPUT_SCHEME 1
@@ -276,30 +281,33 @@ static void show_version(void)
276281
fprintf(stdout, "%s version %s libcurl/%s [built-with %s]\n",
277282
PROGNAME, TRURL_VERSION_TXT, data->version, LIBCURL_VERSION);
278283
fprintf(stdout, "features:");
279-
#ifdef SUPPORTS_PUNYCODE
280-
if(supports_puny)
281-
fprintf(stdout, " punycode");
282-
#endif
283-
#ifdef SUPPORTS_ALLOW_SPACE
284-
fprintf(stdout, " white-space");
285-
#endif
286-
#ifdef SUPPORTS_ZONEID
287-
fprintf(stdout, " zone-id");
284+
#ifdef SUPPORTS_IMAP_OPTIONS
285+
if(supports_imap)
286+
fprintf(stdout, " imap-options");
288287
#endif
289-
#ifdef SUPPORTS_URL_STRERROR
290-
fprintf(stdout, " url-strerror");
288+
#ifdef SUPPORTS_NO_GUESS_SCHEME
289+
fprintf(stdout, "no-guess-scheme");
291290
#endif
292291
#ifdef SUPPORTS_NORM_IPV4
293292
fprintf(stdout, " normalize-ipv4");
294293
#endif
295-
#ifdef SUPPORTS_IMAP_OPTIONS
296-
if(supports_imap)
297-
fprintf(stdout, " imap-options");
294+
#ifdef SUPPORTS_PUNYCODE
295+
if(supports_puny)
296+
fprintf(stdout, " punycode");
298297
#endif
299298
#ifdef SUPPORTS_PUNY2IDN
300299
if(supports_puny)
301300
fprintf(stdout, " punycode2idn");
302301
#endif
302+
#ifdef SUPPORTS_URL_STRERROR
303+
fprintf(stdout, " url-strerror");
304+
#endif
305+
#ifdef SUPPORTS_ALLOW_SPACE
306+
fprintf(stdout, " white-space");
307+
#endif
308+
#ifdef SUPPORTS_ZONEID
309+
fprintf(stdout, " zone-id");
310+
#endif
303311

304312
fprintf(stdout, "\n");
305313
exit(0);
@@ -982,7 +990,7 @@ static const struct var *setone(CURLU *uh, const char *setline,
982990

983991
if(conditional) {
984992
char *piece;
985-
rc = curl_url_get(uh, v->part, &piece, 0);
993+
rc = curl_url_get(uh, v->part, &piece, CURLU_NO_GUESS_SCHEME);
986994
if(!rc) {
987995
skip = true;
988996
curl_free(piece);

0 commit comments

Comments
 (0)