Commit abca372
committed
api: decode query string values only once
`get_string_var()` ran `mg_url_decode()` over the value `mg_get_var()`
returns, but `mg_get_var()` has already decoded it: we leave CivetWeb's
`decode_query_string` at its default `no`, so the query string arrives raw
and CivetWeb decodes it exactly once when extracting a variable.
The second pass changed the value again. `?item=a%2541b` became `aAb`
instead of `a%41b`, and any value containing a space or a `+` made
`mg_url_decode()` return `-1`, so the parameter silently read as absent.
This was harmless enough while `?item=` did not exist, but it is not any
more: we now compare the (once-decoded) path item with the (twice-decoded)
query item and answer 400 when they disagree, so a client naming a group
with a `%` in it got its request rejected.
Return what `mg_get_var()` gives us. Variable *names* are still matched
against the raw query string, so the percent-encoded names in `queries.c`
(e.g. `order%5B0%5D%5Bdir%5D`) keep working.
Adds pytest coverage for both cases: a group whose name contains `%`
addressed through path and `?item=` at once, and one containing a space
addressed through `?item=` alone.
Signed-off-by: DL6ER <dl6er@dl6er.de>1 parent 5e5338c commit abca372
2 files changed
Lines changed: 36 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
438 | 420 | | |
439 | 421 | | |
440 | 422 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
549 | 579 | | |
550 | 580 | | |
551 | 581 | | |
| |||
0 commit comments