curl-converter icon indicating copy to clipboard operation
curl-converter copied to clipboard

Better handling of values containing backslashes

Open jasonmccreary opened this issue 3 years ago • 5 comments
trafficstars

Currently backslashes (and possibly other characters) are being lost from values as they are passed through Artisan. These need to be escaped so they are preserved in the final output. An appropriately placed call to addslashes should to the trick.

Example curl command:

curl --request POST https://example.com/pdf/extract --header 'Content-Type: multipart/form-data' --form 'file=C:\Users\secret\files\007.pdf'

jasonmccreary avatar Oct 17 '22 20:10 jasonmccreary

Seems like an issue in how the Http client receives/parses the option. Will some source diving later.

Treggats avatar Oct 18 '22 09:10 Treggats

The input is parsed by the StringInput class, which tokenises the input. Which is fine, but there it strips the slashes. Which in turn is passed back into our CurlCommand.

I'm doing some more digging wether or not it's possible to adapt the tokenisation, or if there's a way around this.

// vendor/symfony/console/Input/StringInput.php:49
private function tokenize(string $input): array
{
    (..)
    } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) {
        $token .= stripcslashes(substr($match[0], 1, -1));
    }
    (..)
}

Treggats avatar Oct 19 '22 07:10 Treggats

@Treggats, again, I think if we addclashes before calling Artisan would solve the issue.

jasonmccreary avatar Oct 19 '22 10:10 jasonmccreary

@Treggats, again, I think if we addclashes before calling Artisan would solve the issue.

For sure, but when calling this command it's parsed by the base command class. That's where the issue is.

Treggats avatar Oct 19 '22 10:10 Treggats

Interesting. I would still think there is a way to add slashes before passing the parameters to Artisan. Then again, can't be the only devs to pass slashed values to Artisan commands. So there's probably some option or double output happening elsewhere.

I'll take a look.

jasonmccreary avatar Oct 19 '22 10:10 jasonmccreary