manticoresoftware / manticoresoftware/buddy-core
A little problem with URL parsing
- Dominant language
- PHP
- Stars
- 3
- Forks
- 0
- Avg merge
- 18h 6m
- Merged PRs (30d)
- 1
Description
In the code below, the path of the URL is processed with rtrim and ltrim.
This process trims the "?" at the end, but it cannot be processed when parameters are included, such as /_bulk?timeout=60s.
* src/Network/Request.php
```
protected function parseOrFail(array $payload): static {
static::validateInputFields($payload, static::PAYLOAD_FIELDS);
// Checking if request format and endpoint are supported
$this->path = rtrim(ltrim($payload['message']['path_query'], '/'), '?'); # here!
```
I understand that it currently evaluates endpoints containing parameters such as "sql?mode=raw".
I don't think this implementation is clean.
In the first place, PHP has a parse_url() function, so it may be easier to implement using that function.
And I think it's better to evaluate paths and parameters separately. Also in the future.
```
$origin = "/_bulk?timeout=60s";
$pathInfo = parse_url($origin);
var_dump($pathInfo);
# array(2) {
# ["path"]=>
# string(6) "/_bulk"
# ["query"]=>
# string(11) "timeout=60s"
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Begin in src/Network/Request.php at parseOrFail and trace how path_query is consumed after the assignment. Compare requests such as /_bulk?timeout=60s and sql?mode=raw; done means paths and query parameters are handled separately without breaking supported endpoints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100