Skip to content

Commit 61e8698

Browse files
fix: cmpfunc prefix overlap sorting and avoid integer truncation
1 parent afbe098 commit 61e8698

2 files changed

Lines changed: 69 additions & 5 deletions

File tree

tests.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,33 @@
764764
"query=user=me"
765765
]
766766
},
767+
"excludes": [
768+
"uppercase-hex"
769+
],
767770
"expected": {
768771
"stdout": "https://curl.se/hello?user%3dme\n",
769772
"stderr": "",
770773
"returncode": 0
771774
}
772775
},
776+
{
777+
"input": {
778+
"arguments": [
779+
"--url",
780+
"https://curl.se/hello",
781+
"--set",
782+
"query=user=me"
783+
]
784+
},
785+
"required": [
786+
"uppercase-hex"
787+
],
788+
"expected": {
789+
"stdout": "https://curl.se/hello?user%3Dme\n",
790+
"stderr": "",
791+
"returncode": 0
792+
}
793+
},
773794
{
774795
"input": {
775796
"arguments": [
@@ -2183,12 +2204,37 @@
21832204
"query:=a&b&a%26b"
21842205
]
21852206
},
2207+
"excludes": [
2208+
"uppercase-hex"
2209+
],
21862210
"expected": {
21872211
"stdout": "http://localhost/ABC%5c%5c?a&b&a%26b\n",
21882212
"returncode": 0,
21892213
"stderr": ""
21902214
}
21912215
},
2216+
{
2217+
"input": {
2218+
"arguments": [
2219+
"-s",
2220+
"scheme:=http",
2221+
"-s",
2222+
"host:=localhost",
2223+
"-s",
2224+
"path:=/ABC%5C%5C",
2225+
"-s",
2226+
"query:=a&b&a%26b"
2227+
]
2228+
},
2229+
"required": [
2230+
"uppercase-hex"
2231+
],
2232+
"expected": {
2233+
"stdout": "http://localhost/ABC%5C%5C?a&b&a%26b\n",
2234+
"returncode": 0,
2235+
"stderr": ""
2236+
}
2237+
},
21922238
{
21932239
"input": {
21942240
"arguments": [
@@ -2891,12 +2937,32 @@
28912937
"path=%61"
28922938
]
28932939
},
2940+
"excludes": [
2941+
"uppercase-hex"
2942+
],
28942943
"expected": {
28952944
"stdout": "https://example.com/one/tao/%2fB/%2561\n",
28962945
"stderr": "",
28972946
"returncode": 0
28982947
}
28992948
},
2949+
{
2950+
"input": {
2951+
"arguments": [
2952+
"https://example.com/one/t%61o/%2F%42/",
2953+
"--append",
2954+
"path=%61"
2955+
]
2956+
},
2957+
"required": [
2958+
"uppercase-hex"
2959+
],
2960+
"expected": {
2961+
"stdout": "https://example.com/one/tao/%2FB/%2561\n",
2962+
"stderr": "",
2963+
"returncode": 0
2964+
}
2965+
},
29002966
{
29012967
"input": {
29022968
"arguments": [

trurl.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,10 @@ static void qpair2query(CURLU *uh, struct option *o)
15951595
/* sort case insensitively */
15961596
static int cmpfunc(const void *p1, const void *p2)
15971597
{
1598-
int i;
1598+
size_t i;
15991599
size_t len1 = ((const struct string *)p1)->len;
16001600
size_t len2 = ((const struct string *)p2)->len;
1601-
int len = (int)(len1 < len2 ? len1 : len2);
1601+
size_t len = len1 < len2 ? len1 : len2;
16021602

16031603
for(i = 0; i < len; i++) {
16041604
char c1 = ((const struct string *)p1)->str[i] | ('a' - 'A');
@@ -1607,9 +1607,7 @@ static int cmpfunc(const void *p1, const void *p2)
16071607
return c1 - c2;
16081608
}
16091609

1610-
if(len1 != len2)
1611-
return len1 < len2 ? -1 : 1;
1612-
return 0;
1610+
return (len1 > len2) - (len1 < len2);
16131611
}
16141612

16151613
static bool sortquery(struct option *o)

0 commit comments

Comments
 (0)