Skip to content

Commit 68986f4

Browse files
committed
fix hv_parse_url processing '#' and '?' order priority bug
1 parent 1e3dd55 commit 68986f4

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

base/hbase.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,24 @@ int hv_parse_url(hurl_t* stURL, const char* strURL) {
521521
if (ep == end) return 0;
522522
// /path
523523
sp = ep;
524-
ep = strchr(sp, '?');
525-
if (ep == NULL) ep = end;
524+
const char* query = strchr(sp, '?');
525+
const char* fragment = strchr(sp, '#');
526+
if (query && fragment) ep = MIN(query, fragment);
527+
else if (query == NULL && fragment) ep = fragment;
528+
else if (query == NULL) ep = end;
529+
else ep = query;
526530
stURL->fields[HV_URL_PATH].off = sp - begin;
527531
stURL->fields[HV_URL_PATH].len = ep - sp;
528532
if (ep == end) return 0;
529-
// ?query
530-
sp = ep + 1;
531-
ep = strchr(sp, '#');
532-
if (ep == NULL) ep = end;
533-
stURL->fields[HV_URL_QUERY].off = sp - begin;
534-
stURL->fields[HV_URL_QUERY].len = ep - sp;
535-
if (ep == end) return 0;
533+
if (ep != fragment) {
534+
// ?query
535+
sp = ep + 1;
536+
ep = fragment;
537+
if (ep == NULL) ep = end;
538+
stURL->fields[HV_URL_QUERY].off = sp - begin;
539+
stURL->fields[HV_URL_QUERY].len = ep - sp;
540+
if (ep == end) return 0;
541+
}
536542
// #fragment
537543
sp = ep + 1;
538544
ep = end;

0 commit comments

Comments
 (0)