Skip to content

Commit

Permalink
trurl: fix handling of query pair with blank left side
Browse files Browse the repository at this point in the history
Passing a query pair with a blank left side like '=a' was similarly
mistreated.

Follow-up to 06b5945

Added test case to verify.
  • Loading branch information
bagder committed Sep 10, 2024
1 parent 06b5945 commit 69c812a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2856,5 +2856,17 @@
"stderr": "",
"returncode": 0
}
},
{
"input": {
"arguments": [
"http://example.org/?=1&b=2&c=&=3"
]
},
"expected": {
"stdout": "http://example.org/?=1&b=2&c=&=3\n",
"stderr": "",
"returncode": 0
}
}
]
24 changes: 17 additions & 7 deletions trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,12 +1378,20 @@ static struct string *memdupzero(char *source, size_t len, bool *modified)
else {
int llen;
int rlen;
int leftside;
int rightside;

/* decode both sides */
left = decodequery(source, (int)(sep - source), &llen);
if(!left)
goto error;
leftside = (int)(sep - source);
if(leftside) {
left = decodequery(source, leftside, &llen);
if(!left)
goto error;
}
else {
left = NULL;
llen = 0;
}

/* length on the right side of '=': */
rightside = (int)len - (int)(sep - source) - 1;
Expand All @@ -1400,16 +1408,18 @@ static struct string *memdupzero(char *source, size_t len, bool *modified)
}

/* encode both sides again */
el = encodequery(left, llen);
if(!el)
goto error;
if(left) {
el = encodequery(left, llen);
if(!el)
goto error;
}
if(right) {
er = encodequery(right, rlen);
if(!er)
goto error;
}

encode = curl_maprintf("%s=%s", el, er ? er : "");
encode = curl_maprintf("%s=%s", el ? el : "", er ? er : "");
if(!encode)
goto error;
}
Expand Down

0 comments on commit 69c812a

Please sign in to comment.