Open Benjamin-Loison opened 3 months ago
It seems that currently the algorithm rebuilds the command as --data-raw '$...'
which is an issue in the context of Benjamin_Loison/OneDrive/issues/6.
Also before blob/main/tools/minimizeCURL.py#L151-L228 have to be considered as it rebuilds incorrectly the command.
A shameful, probably introducing a security flaw, fix is:
command = command.replace(" --data-raw '$", " --data-raw $'")
But to put where? I guess in isCommandStillFine
.
Related to #171.
Alternatively can replace --data-raw $'...'
with --data-raw "..."
it seems.
Maybe just '...'
does not interpret some characters like \r
and \n
. It seems that "..."
too even if escape them and "
.
Even escaping \
, does not make "..."
work for:
So I exceptionally minimized by hand.
echo $'-----------------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nContent-Disposition: form-data; name="no_individu"\r\n\r\nXXXXXX\r\n-----------------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nContent-Disposition: form-data; name="acti"\r\n\r\nXX\r\n-----------------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXX--\r\n'
I am unable to reproduce these new lines without $
.
Otherwise maybe could rely on a command line converter.
The Unix Stack Exchange answer 48122 may help as well as its comments.
Related to Webscrap_any_website/issues/29.
import shlex
command = "curl --data-raw $'\''"
# command = "curl --data-raw $'a'"
# works fine
shlex.split(command)
help(shlex.split)
Removing $
does not help.
import shlex
command = "curl --data-raw $'\''"
print(shlex.split(command, posix = False))
['curl', '--data-raw', "$'''"]
help(shlex.join)
import shlex
command = "curl --data-raw $'\''"
commandSplitted = shlex.split(command, posix = False)
print(shlex.join(commandSplitted))
curl --data-raw '$'"'"''"'"''"'"''
print(' '.join(commandSplitted))
curl --data-raw $'''
command = "curl --data-raw $'\''"
print(command)
curl --data-raw $'''
import shlex
command = "curl --data-raw $'\\''"
# Equivalent to above `command`.
with open('curl.sh') as f:
command = f.read()
print(command)
commandSplitted = shlex.split(command, posix = False)
print(shlex.join(commandSplitted))
print(' '.join(commandSplitted))
Using ' '.join(...)
requires to manage quoting arguments on our own it seems.
For big file modified above diff with:
Copy as {PowerShell,Fetch} do not seem to help.
On Windows:
Copy as cURL (Windows) does not use $'
. But does not work as wanted on Linux according to echo
to a file and diff
with Copy as cURL (POSIX).
Copy as cURL (POSIX) uses $'
.
What about Chromium on Linux and Windows? See Online_authentication_API/issues/78#issuecomment-2405882.
DuckDuckGo and Google search Command POSIX to Windows converter do not return relevant results it seems.
Note that echo $"a\nb"
does not work while echo $'a\nb'
does.
Maybe latest Python version of shlex
supports this feature.
In fact splitting echo $'a\nb'
and echo 'a\nb'
should return something like ['echo', 'a\nb']
. It is unclear how should keep the $'...'
information.
Can maybe somehow not need $'...'
by expand newlines (but does not seem to apply to other usages of $'...'
) or use a given file for --data-raw
it is possible as far as I remember.
COMMAND = "echo $'a\\nb'"
print(COMMAND)
print(shlex.split(COMMAND))
echo $'a\nb'
['echo', '$a\\nb']
COMMAND = "echo '$a\\nb'"
print(COMMAND)
print(shlex.split(COMMAND))
echo '$a\nb'
['echo', '$a\\nb']
echo '$a\nb'
$a\nb
COMMAND = "echo $'a\\nb'"
print(COMMAND)
print(shlex.split(COMMAND, posix = False))
echo $'a\nb'
['echo', "$'a\\nb'"]
COMMAND = "echo '$a\\nb'"
print(COMMAND)
print(shlex.split(COMMAND, posix = False))
echo '$a\nb'
['echo', "'$a\\nb'"]
In the case of Online authentication API, this issue may be due to my complex passwords, using, if possible, passwords without special characters may help. Otherwise use special character that do not seem to require some kind of escape as $'...'
seems to provide.
https://github.com/Benjamin-Loison/YouTube-operational-API/blob/d61488fbe0becf6d2a6ebc97761e5b87a8facd3f/tools/minimizeCURL.py#L43
See the Unix Stack Exchange answer 115614.
http://wiki.bash-hackers.org/syntax/quoting is a quite empty page (even from source point of view and
https://
does not help). https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html