Skip to content

Commit

Permalink
support conditionally set scheme
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
bagder committed Jun 13, 2024
1 parent 21fff73 commit d15647d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
29 changes: 29 additions & 0 deletions tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2572,5 +2572,34 @@
"returncode": 10,
"stdout": ""
}
},
{
"required": ["no-guess-scheme"],
"input": {
"arguments": [
"example.com",
"--set",
"scheme?=https"
]
},
"expected": {
"stdout": "https://example.com/\n",
"stderr": "",
"returncode": 0
}
},
{
"input": {
"arguments": [
"ftp://example.com",
"--set",
"scheme?=https"
]
},
"expected": {
"stdout": "ftp://example.com/\n",
"stderr": "",
"returncode": 0
}
}
]
38 changes: 23 additions & 15 deletions trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ typedef enum {
#if CURL_AT_LEAST_VERSION(7,30,0)
#define SUPPORTS_IMAP_OPTIONS
#endif
#if CURL_AT_LEAST_VERSION(8,9,0)
#define SUPPORTS_NO_GUESS_SCHEME
#else
#define CURLU_NO_GUESS_SCHEME 0
#endif

#define OUTPUT_URL 0 /* default */
#define OUTPUT_SCHEME 1
Expand Down Expand Up @@ -276,30 +281,33 @@ static void show_version(void)
fprintf(stdout, "%s version %s libcurl/%s [built-with %s]\n",
PROGNAME, TRURL_VERSION_TXT, data->version, LIBCURL_VERSION);
fprintf(stdout, "features:");
#ifdef SUPPORTS_PUNYCODE
if(supports_puny)
fprintf(stdout, " punycode");
#endif
#ifdef SUPPORTS_ALLOW_SPACE
fprintf(stdout, " white-space");
#endif
#ifdef SUPPORTS_ZONEID
fprintf(stdout, " zone-id");
#ifdef SUPPORTS_IMAP_OPTIONS
if(supports_imap)
fprintf(stdout, " imap-options");
#endif
#ifdef SUPPORTS_URL_STRERROR
fprintf(stdout, " url-strerror");
#ifdef SUPPORTS_NO_GUESS_SCHEME
fprintf(stdout, "no-guess-scheme");
#endif
#ifdef SUPPORTS_NORM_IPV4
fprintf(stdout, " normalize-ipv4");
#endif
#ifdef SUPPORTS_IMAP_OPTIONS
if(supports_imap)
fprintf(stdout, " imap-options");
#ifdef SUPPORTS_PUNYCODE
if(supports_puny)
fprintf(stdout, " punycode");
#endif
#ifdef SUPPORTS_PUNY2IDN
if(supports_puny)
fprintf(stdout, " punycode2idn");
#endif
#ifdef SUPPORTS_URL_STRERROR
fprintf(stdout, " url-strerror");
#endif
#ifdef SUPPORTS_ALLOW_SPACE
fprintf(stdout, " white-space");
#endif
#ifdef SUPPORTS_ZONEID
fprintf(stdout, " zone-id");
#endif

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

if(conditional) {
char *piece;
rc = curl_url_get(uh, v->part, &piece, 0);
rc = curl_url_get(uh, v->part, &piece, CURLU_NO_GUESS_SCHEME);
if(!rc) {
skip = true;
curl_free(piece);
Expand Down

0 comments on commit d15647d

Please sign in to comment.