Skip to content
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

%{urlnum} variable does not increment for globbed URLs #7342

Closed
jay opened this issue Jul 4, 2021 · 1 comment
Closed

%{urlnum} variable does not increment for globbed URLs #7342

jay opened this issue Jul 4, 2021 · 1 comment
Labels
cmdline tool not-a-curl-bug This is not a bug in curl

Comments

@jay
Copy link
Member

jay commented Jul 4, 2021

I did this

Коваленко Анатолий Викторович reported on the curl-library mailing list that %{urlnum} does not increment for globbed URLs. For example:

> curld.exe -s -w "%{urlnum}\n" -o "#1.tmp" "httpbin.org/get?[1-2]"
0
0

> curld.exe -s -w "%{urlnum}\n" -o "1.tmp" "httpbin.org/get?1" -o "2.tmp" "httpbin.org/get?2"
0
1

I expected the following

urlnum is documented as The URL index number of this transfer, 0-indexed.

curl/libcurl version

Since it was added in 7.75.0

analysis

struct getout num is the 0-indexed URL number from the command line.
struct State urlnum is the 1-indexed number of the currently parsed globbed URL or 1 if not globbed.
The glob state of the current URL is also kept track of via State.li which is checked to reset the glob state and force reglob (but just skimming this I don't understand why that is necessary).
In single_transfer State.urlnum is assigned to a local urlnum, and shortly after getout.num is assigned to per_transfer urlnum.
It appears the only purpose of the per_transfer.urlnum is to save the url number for the write-out variable %{urlnum}.

In order to fix this we'd have to keep track of the cumulative URL count from globbing previous URLs.

For example httpbin.org/get/[1-2] httpbin.org/get/[3-4] httpbin.org/get/5 deglobs to:

httpbin.org/get/1

state->urlnum: 2
local urlnum: 2
state->li: 0
per->urlnum: 0
(expected) per->urlnum: 0

httpbin.org/get/2

state->urlnum: 2
local urlnum: 2
state->li: 1
per->urlnum: 0
(expected) per->urlnum: 1

httpbin.org/get/3

state->urlnum: 2
local urlnum: 2
state->li: 0
per->urlnum: 1
(expected) per->urlnum: 2

httpbin.org/get/4

state->urlnum: 2
local urlnum: 2
state->li: 1
per->urlnum: 1
(expected) per->urlnum: 3

httpbin.org/get/5

state->urlnum: 1
local urlnum: 1
state->li: 0
per->urlnum: 2
(expected) per->urlnum: 4

@bagder
Copy link
Member

bagder commented Jul 4, 2021

I don't think the index should include globbing, simply because it makes it really hard to understand which URL it referss to when for example the first URL uses globing and the second doesn't.

@bagder bagder added the not-a-curl-bug This is not a bug in curl label Jul 5, 2021
jay added a commit to jay/curl that referenced this issue Jul 9, 2021
Reported-by: Коваленко Анатолий Викторович

Fixes curl#7342
Closes #xxxx
@jay jay closed this as completed in 5d3c409 Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmdline tool not-a-curl-bug This is not a bug in curl
Development

Successfully merging a pull request may close this issue.

2 participants