-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curl tool globbing range [1-1] doesn't work #1238
Comments
Please fill out the template, it is not filled out |
Sorry about the initial post missing information - snafu with github editor. Addendum - current version information: Old version is unknown - lost in hard disk crash. Downloaded latest curl as part of recovery. |
[1-1] was supported starting in b169aa2 but it likely broke in 5ca96cb which has glob fail when this is true: diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c
index 0edfac6..b0e46b2 100644
--- a/src/tool_urlglob.c
+++ b/src/tool_urlglob.c
@@ -220,8 +220,9 @@ static CURLcode glob_range(URLGlob *glob, char **patternp,
*posp += (pattern - *patternp);
- if((rc != 3) || (min_c >= max_c) || ((max_c - min_c) > ('z' - 'a')) ||
- (step <= 0) )
+ if(rc != 3 || step <= 0 ||
+ (min_c == max_c && step != 1) ||
+ (min_c != max_c && (min_c > max_c || (max_c - min_c) > ('z' - 'a'))))
/* the pattern is not well-formed */
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
@@ -230,9 +231,9 @@ static CURLcode glob_range(URLGlob *glob, char **patternp,
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
pat->content.CharRange.max_c = max_c;
- if(multiply(amount, (pat->content.CharRange.max_c -
+ if(multiply(amount, ((pat->content.CharRange.max_c -
pat->content.CharRange.min_c) /
- pat->content.CharRange.step + 1) )
+ pat->content.CharRange.step + 1)))
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
}
else if(ISDIGIT(*pattern)) {
@@ -293,7 +294,9 @@ static CURLcode glob_range(URLGlob *glob, char **patternp,
fail:
*posp += (pattern - *patternp);
- if(!endp || (min_n > max_n) || (step_n > (max_n - min_n)) || !step_n)
+ if(!endp || !step_n ||
+ (min_n == max_n && step_n != 1) ||
+ (min_n != max_n && (min_n > max_n || step_n > (max_n - min_n))))
/* the pattern is not well-formed */
return GLOBERROR("bad range", *posp, CURLE_URL_MALFORMAT);
@@ -303,9 +306,9 @@ static CURLcode glob_range(URLGlob *glob, char **patternp,
pat->content.NumRange.max_n = max_n;
pat->content.NumRange.step = step_n;
- if(multiply(amount, (pat->content.NumRange.max_n -
- pat->content.NumRange.min_n) /
- pat->content.NumRange.step + 1) )
+ if(multiply(amount, ((pat->content.NumRange.max_n -
+ pat->content.NumRange.min_n) /
+ pat->content.NumRange.step + 1)))
return GLOBERROR("range overflow", *posp, CURLE_URL_MALFORMAT);
}
else |
I made them not work (at some point when I went through and tightened up the range handling), because 1-1 isn't really range, it is just a single value and thus I think it is more likely to hint that there was a mistake made than that the user actually asks for a single value written in a clumsy way... |
You may have a script that sets the range for a series of transfers, and maybe there's only one transfer to make. @rdsteed what's your use case? |
@jay that is exactly the case. It is from a Windows batch file wrapping a curl command for downloading of podcast files. 1 to many years, 1 to many months, 1 to many days in one command. It also facilitated the #n notation in curl output for naming the downloads. @Badger I found the [1-1] consistent with being able to use (a1..a1) notation in Excel spreadsheets to specify a single cell range or [1:2] to specify a single list item in Python. Of course, it doesn't make a whole lot of sense in these examples where constants are used, but it actually makes a lot of sense when the curl command is in a batch file and there is substitution of command arguments. |
ok, so let's fix this and add a test or two to make sure it sticks |
Thanks. [start-stop:step] With this in mind I don't believe one trip loops should cause an error, but a warning in verbose mode could be helpful. Finally, though I have a reading knowledge of C, I've never written in it. Otherwise, I would have contributed a pull request or a patch. Thanks for doing this. |
Oops. Didn't mean to close. Clicked the wrong button. Still not used to this new touchpad. |
@jay, will you bring this forward? You can probably make a test for it based on test87. If not, let me know and I can work on it. |
Ok, I added a test and made a branch for review. It is slightly different from my patch above because I had to make some adjustments to allow for [a-a:1]. |
Looks good to me! |
I recently upgraded curl.
My old version allowed allowed the curl command to use single value ranges eg [1-1]. In the new version this causes an error.
Is there any chance that curl could revert to the older, more permissive behavior?
The text was updated successfully, but these errors were encountered: