Page 1 of 1
reading encoded URL from file or stdout error
Posted: Fri Feb 06, 2015 11:27 pm
by tz8
Hi,
i have a weird thing i need help with:
var uri = HTTP.encodeURIComponent( "
http://bla.foo.bar/foo/bar.xml" );
var f = new File( "/tmp/foo.txt" );
f.open( File.WriteOnly );
f.write( uri );
f.close();
f.open( File.ReadOnly );
var uri_read = f.read();
f.close();
uri_read;
the file /tmp/foo.txt looks like expected:
http%3A%2F%2Fbla.foo.bar%2Ffoo%2Fbar.xml
but what Switch is making with it is:
Script evaluation result: httpAFFbla.foo.barFfooFbar.xml [type: QString]
i get the exact same result if the string is being read by Process.readStdout()
anything i'm doing completely wrong here? Or is Switch just behaving badly here?
Cheers,
tz8
reading encoded URL from file or stdout error
Posted: Mon Feb 09, 2015 4:24 pm
by freddyp
If the file looks OK, then it is OK.
In s.log messages a % sign followed by a number has a special meaning, so messages that contain these combinations get messed up. And in this case that is of course really annoying. But rest assured, it is only the logging, the string itself is fine.
Freddy
Re: reading encoded URL from file or stdout error
Posted: Thu Feb 26, 2015 12:02 pm
by tz8
everyone, to wrap this up...
the error i had was because i needed logging to find out why something that was working on the command line was not working out of switch - and logging URLencoded stuff messes up logging.
Why was the command failing in switch that was perfectly fine on the command line? Well...
Code: Select all
var args = new Array();
args.push( s.getPropertyValue( "CurlPath" ) );
args.push( "-s" ); // silent
args.push( "-k" ); // ignore cert chain validation errors aka 'insecure'
args.push( "-H" ); // send Header
args.push( "'Authorization: " + sas_key + "'" );
args.push( "-H" ); // another Header?
args.push( "Content-Type: text/xml" ); // sure
args.push( "-X" ); // what to do
args.push( "POST" ); // yeah, we'll POST
args.push( "-d" ); // what'll we POST?
args.push( "@" + job.getPath() ); // the XML coming as the job file
args.push( uri ); // and we'll post it right to this URL
args.push( "--write-out" );
args.push( "'%{http_code}'" );
args.push( "--output" );
args.push( resultFile );
var curlProc = new Process( args );
curlProc.start();
curlProc.waitForFinished();
var resultCode = curlProc.readStdout();
see it? Let me point it out:
Code: Select all
args.push( "'Authorization: " + sas_key + "'" );
i had to add quotes to this on the command line as there is a space in the Auth Header. So i added the quotes in Switch as well! Which is a bad idea, as Switch is adding quotes to any element of an array that is being passed to a process() IF IT HAS SPACES IN THERE! So.... double quotes. And no decent logging possible.
I changed the line to
Code: Select all
args.push( "Authorization: " + sas_key );
and was fine. But angry. Guess i expected Switch to check if the argument already has quotes. Or i could have checked the process() documentation and see this:
Process( command : String[ ] )
Same as above, except that command is an Array of strings, where the first item is the name of the program and the following items are command line arguments. This version is useful if you have arguments that contain spaces or other characters that would need to be quoted if you just passed a single string command line, since it takes care of the quoting for you.
live and learn and warn others
Cheers,
Thorsten