invalid URL escape "%" when docker push - docker

I set up a registry at docker-registry.elektron.space and when I want to push an image with $ docker push docker-registry.elektron.space/boxbeat-media-server, the upload animation is running in loop for each entity passing from "Pushing" state to "Retrying in X seconds".
After a while I get this error:
failed to parse Location header "https://docker-registry.elektron.space/v2/boxbeat-media-server/blobs/uploads/56244149-c196-439a-85bf-af1121e0b84b%?_state=h1lqY-NljkLbgzTCjd8jxcfdscojPHApblWu-45ISK57Ik5hbWUiOiJib3hiZWF0LW1lZGlhLXNlcnZlciIsIlVVSUQiOiI1NjI0NDE0OS1jMTk2LTQzOWEtODViZi1hZjExMjFlMGI4NGIiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMjAtMDMtMDFUMTU6MzI6NTAuMzcxNjc5NTc5WiJ9": parse https://docker-registry.elektron.space/v2/boxbeat-media-server/blobs/uploads/56244149-c196-439a-85bf-af1121e0b84b%?_state=h1lqY-NljkLbgzTCjd8jxcfdscojPHApblWu-45ISK57Ik5hbWUiOiJib3hiZWF0LW1lZGlhLXNlcnZlciIsIlVVSUQiOiI1NjI0NDE0OS1jMTk2LTQzOWEtODViZi1hZjExMjFlMGI4NGIiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMjAtMDMtMDFUMTU6MzI6NTAuMzcxNjc5NTc5WiJ9: invalid URL escape "%"
In a readable way:
failed to parse Location header
"https://docker-registry.elektron.space/v2/boxbeat-media-server/blobs/uploads/
56244149-c196-439a-85bf-af1121e0b84b%?_state=
h1lqY-NljkLbgzTCjd8jxcfdscojPHApblWu-45ISK57Ik5hbWUiOiJib3hiZWF0LW1lZGlhLXNlcnZlciIsIlVVSUQiOiI1NjI0NDE0OS1jMTk2LTQzOWEtODViZi1hZjExMjFlMGI4NGIiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMjAtMDMtMDFUMTU6MzI6NTAuMzcxNjc5NTc5WiJ9":
parse https://docker-registry.elektron.space/v2/boxbeat-media-server/blobs/uploads/
56244149-c196-439a-85bf-af1121e0b84b%?_state=
h1lqY-NljkLbgzTCjd8jxcfdscojPHApblWu-45ISK57Ik5hbWUiOiJib3hiZWF0LW1lZGlhLXNlcnZlciIsIlVVSUQiOiI1NjI0NDE0OS1jMTk2LTQzOWEtODViZi1hZjExMjFlMGI4NGIiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMjAtMDMtMDFUMTU6MzI6NTAuMzcxNjc5NTc5WiJ9:
invalid URL escape "%"
Where does this "%" come from? I thought this could come from zsh then I tried to run it with bash but same result.
Any idea?

The issue is that a % sign is used to initiate an escape sequence in url encoding. You need to escape the % itself.
So in your case you should replace the % with %25 which is the escaped form if it. That way you don't get the error because the parser doesn't think an escape sequence is about to start when it sees the %
... /uploads/56244149-c196-439a-85bf-af1121e0b84b%25 ...
This article can also help to understand things better. Even though its about javascript, the information is applicable much broader.
You can lookup escape sequences on this page.

Related

How to maintain the escaped quotes in an expression in Spring Cloud Data Flow?

When I configure my stream to be depoyed, in which I'm using a processor (transform, script or http-request), in the "expression" atribute I need to set an expression that contains quotes and double quotes (escaped). The expression works properly the first time I set and allows to deploy the stream, but if I undeploy the stream and try again to deploy it, the spring cloud data flow throws state machine exception because the backslashes used to escape the double quotes are removed.
I already follow the considerations in the Spaces and Quotes documentation, but I think that it only applies to the streams definition and not to the deployment time.
The URL of the spaces and quotes documentarion is: https://docs.spring.io/spring-cloud-dataflow/docs/current-SNAPSHOT/reference/htmlsingle/#shell-white-space
And the sample of the type of expression required:
expression="new String('{\"size\": 1,\"sort\": {\"timestamp\": \"desc\"},\"query\": {\"prefix\": {\"integrationname\": \"63320e0d313862934667225f\"}}}')"
The stream could be as simple as:
http | transform | log
The firs time the expression is set looks like as follows:
expression="new String('{\"size\": 1,\"sort\": {\"timestamp\": \"desc\"},\"query\": {\"prefix\": {\"integrationname\": \"63320e0d313862934667225f\"}}}')"
Deploying correctly the stream.
Once the stream is undeployed and try to deploy it again, the espression looks like:
expression="new String('{"size": 1,"sort\": {"timestamp": "desc"},"query": {"prefix": {"integrationname": "63320e0d313862934667225f"}}}')"
Where the backslashes were removed, causing the state machine exception because of the unescaped double quotes.
Thanks in advance
We are looking at Issue #5145 and will update the issue when we have fixed it.
In the meantime I would suggest using the spring-cloud-dataflow-shell or the REST API to automate deployments where you provide the properties every time as needed.

Linux expect newline

I have a custom package I want to install automatically in my docker using expect.
The first thing the package asks me to do is press Enter to continue, then it prints another 2 empty lines then it waits for an input.
My expect script :
#!/usr/bin/expect -f
set timeout -1
spawn ./install
expect "\n"
send -- "\n"
But as you can see in the image, it just runs the installer and exits.
I tried removing the expect "\n" so only send -- "\n" will execute but now even the install message doesn't appear (tried with set timeout 1000 before send and it also didn't work)
Any ideas?
P.S : This is a link to the package if anyone wants to have a go at it:
https://www.bayometric.com/downloads/digital-persona/DP_UareU_Linux223_20140429.2.zip
(the installer is inside DP-UareU-RTE-2.2.3-1.20140429_1533.tar.gz)
expect "\n" match a linefeed exactly, I think this is not what your program is sending.
To wait for a Shell prompt you can use expect "%" or expect "*" to match anything.
If you need to make sure you're dealing with the right prompt you may be able to use something like expect "*Linux Installation*".
Also don't send \n but \r for the enter key :
#!/usr/bin/expect
spawn ./install
expect "*Linux Installation*"
send "\r"
expect eof
Note that the default flag is -gl for glob pattern matching but you can also use the -re flag for regular expression matching.

Objective-C Remove ANSI Color Control Codes

I'm building an iOS application that communicates with a remote server. In this case, I'm executing commands using SSH, however, the response coming back from the server is coming in the form of what appears to be hexadecimal. My delegate function for handling responses from a remote server takes the response argument as an NSString, however, this is the content of the string returned (command executed was "ls /" )
ls /\r\n\x1b[0m\x1b[01;34mbin\x1b[0m \x1b[01;34mdev\x1b[0m \x1b[01;36minitrd.img\x1b[0m \x1b[01;34mlib64\x1b[0m \x1b[01;34mmnt\x1b[0m \x1b[01;34mroot\x1b[0m \x1b[01;34msrv\x1b[0m \x1b[01;34musr\x1b[0m\r\n\x1b[01;34mboot\x1b[0m \x1b[01;34metc\x1b[0m \x1b[01;36minitrd.img.old\x1b[0m \x1b[01;34mlost+found\x1b[0m \x1b[01;34mopt\x1b[0m \x1b[01;34mrun\x1b[0m \x1b[01;34msys\x1b[0m \x1b[01;34mvar\x1b[0m\r\n\x1b[01;34mcdrom\x1b[0m \x1b[01;34mhome\x1b[0m \x1b[01;34mlib\x1b[0m \x1b[01;34mmedia\x1b[0m \x1b[01;34mproc\x1b[0m \x1b[01;34msbin\x1b[0m \x1b[30;42mtmp\x1b[0m \x1b[01;36mvmlinuz\x1b[0m'
If this is in fact hexadecimal, how to I convert this back to a readable string for display purposes? If it's not hexadecimal, does anyone know what it is?
EDIT:
Since this is ANSI Color Control Codes, what's the best method to remove them?
prepend "\" to the beginning of the command
$ \ls
or provide handling for the escape sequences (strip, display)

Escape sequence with backslash for NSURL path

I am doing a simple GET request to a remote server with the help of AFNetowkrking.
The path for that call with curl is: /api\?member\=11\&type\=forum and responds with OK200.
But this path in iOS and AFnetworking 2 gets a warning - the backlash is not recognized "unknown escape sequence" and removed from the path, thus the server returns 404.
How can I add this escape sequence to the string so that the server responds with no error?
It is quite rare to have backslash in this type of URL, but if it is needed, add nother one, so there are 2 backslashes. like: member\\=11\\&
You can use [myString stringByReplacingString:withString: to replace #"\" by #""

Powershell: inconsistent/strange behavior with quote parsing?

all! I'm trying to compile a program using PowerShell, but the command is being parsed strangely.
This command executes correctly in cmd.exe:
dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release
But PowerShell executes it as: (blue, navy, purple texts as they appear in PowerShell ISE)
dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release
This spits the following error:
The string starting:
At line:1 char:147
+ dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d"
"src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d <<<< " -D -O -release
is missing the terminator: ".
At line:1 char:163
So it seems to be interpreting a period as a quote. This is peculiar. Has anyone else had this problem with PowerShell?
Things I've tried:
escaping quotes
making sure all quotes are "straight quotes" and not angled
putting a space before quotes (parses correctly, but the program doesn't understand the arguments.)
Thanks,
Charles.
I believe this should do the trick (newlines added for clarity only, and removal of extra quotes):
dmd '-od"bin"' '-of"bin\convHull.exe"' '-I"src"'
src\concSort.d src\fileParser.d src\main.d src\pointLogic.d src\quickHull.d src\stupidHull.d
-D -O -release
Note that in the case where a quote (") is to be passed as part of the argument itself, I surrounded the entire argument with single quotes ('). From the experimentation below it can be seen that only -of"..." needs the quotes about it.
Happy coding.
I can't find a good reference on this exact production, however note the following parsings:
-x"w." -> error: " expected (last " is special)
-x"w."" -> -x"w and ."" (the . starts a new token and the " in that starts
a quote; however, the quotes are not removed)
'-x"w."' -> -x"w." (extra quote fine, neither special)
-x"w" -> -x"w" (no . and " not special)
-x"w"" -> -x"w"" (no . and " not special)
a".b" -> a.b (didn't start with `-`, quotes removed)
a".b -> error: " expected (" is special)
So it does indeed appear to have something to do with the . and - combination (and it might not be exclusive). From the above I believe that a token starting with - does not include the . character as a valid character in the token so the lexer terminates said token and starts a new token -- easily provable with a good EBNF reference, which I don't have.
The best I can find is Appendix C: The PowerShell Grammar:
The ParameterToken rule is used to match cmdlet parameters such as -foo or -
boolProp: . Note that this rule will also match --foobar, so this rule has
to be checked before the --token rule.
<ParameterToken> = -[:letter:]+[:]{0 |1}
However, this is incomplete at best and does not even include a definition of "letter".
I don't have the executable, but this seems to want to work.
$cmd = #'
dmd -od"bin" -of"bin\convHull.exe" -I"src" "src\concSort.d" "src\fileParser.d" "src\main.d" "src\pointLogic.d" "src\quickHull.d" "src\stupidHull.d" -D -O -release
'#
&$cmd

Resources