Re: [j-nsp] Is it possible to pass apostrophe character(ASCII dec code 39) as an argument value to SLAX script?

2018-07-17 Thread Martin T
On Fri, Jul 13, 2018 at 12:35 AM Phil Shafer  wrote:
>
> Martin T writes:
> >aren't you using grave accent("echo -e "\x60"") character? I was using
> >"echo -e "\x27"" character.
>
> Doh!  I read apostrophe (even named the script apos.slax) but my
> brain turned into backtick.
>
> Yes, this looks like a JUNOS bug:
>
> root@box> op apos char "'"
> ''':(null):(2) Invalid expression
> error: runtime error
> error: Evaluating user parameter char failed
>
> The underlaying slax library handles it correctly:
>
> % slaxproc -E -n cs-examples/apos.slax -g -a char "'"
> 
> 
>   got: '
> 
>
> But it looks like this is explicitly handled in slaxproc.c:
>
> quote = strrchr(pvalue, '\"') ? '\'' : '\"';
> tvalue[0] = quote;
> memcpy(tvalue + 1, pvalue, plen);
> tvalue[plen + 1] = quote;
> tvalue[plen + 2] = '\0';
>
> This logic doesn't appear in the JUNOS driver (/usr/libexec/ui/cscript).
> I'll open a PR for this.
>
> There is a limitation in XSLT that one can't mix strings with both
> single and double quotes.  Strange but true.
>
> Thanks,
>  Phil

Thanks for confirming this! Just for information, another interesting
quirk I found is that in the case of non-interactive SSH mode, the ";"
character breaks the command on cli if it is preceded by escaped
double-quote character. I tested this with Net::OpenSSH, Net::SSH2 and
Net::SSH::Expect Perl modules, but one can demonstrate this easily
with OpenSSH client as well. For example:

$ ssh vmx1 'set cli directory "f\"oo;bar"'

error: Cannot set directory to 'f"oo'

error: unknown command: bar
$

In interactive mode, there is no such limitation:

martin@vmx1> set cli directory "f\"oo;bar"
error: Cannot set directory to 'f"oo;bar'

martin@vmx1>



Last problematic printable(dec 32 to dec 126) ASCII character, which I
found, was "\". It seems to work in a way that it escapes the
double-quote character('\"' becomes '"') and reports a syntax error if
"\" isn't followed by any other character.


The reason I found those Junos cli quirks is that I wrote a test
script(https://perldoc.perl.org/Test/More.html), which among other
things, generates a random string of characters from " "(dec 32) to
"~"(dec 126) which becomes an argument value for op script. So in
order to avoid any Junos cli errors, I'm doing following substitutions
to this randomly generated string before returning it to Perl
Net::SSH::Expect module:

# Replace one or more \ character(s) with single _ if the \
character(s) is at the end of the string.
$str =~ s/\\+$/_/;
# Delete all the \ character(s) if they are preceeding a " character.
$str =~ s/\\+"/"/g;
# Delete all ' characters.
$str =~ s/'/_/g;
# Escape the " character.
$str =~ s/"/\\"/g;

return $str;

I'm not saying, that this is perfect, but it is best I have managed to
come up with. I try to preserve the rendomly generated string as much
as possible. As much as I have tested, it seems to work.


regards,
Martin
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] Is it possible to pass apostrophe character(ASCII dec code 39) as an argument value to SLAX script?

2018-07-12 Thread Phil Shafer
Martin T writes:
>aren't you using grave accent("echo -e "\x60"") character? I was using
>"echo -e "\x27"" character.

Doh!  I read apostrophe (even named the script apos.slax) but my
brain turned into backtick.

Yes, this looks like a JUNOS bug:

root@box> op apos char "'"
''':(null):(2) Invalid expression
error: runtime error
error: Evaluating user parameter char failed

The underlaying slax library handles it correctly:

% slaxproc -E -n cs-examples/apos.slax -g -a char "'"


  got: '


But it looks like this is explicitly handled in slaxproc.c:

quote = strrchr(pvalue, '\"') ? '\'' : '\"';
tvalue[0] = quote;
memcpy(tvalue + 1, pvalue, plen);
tvalue[plen + 1] = quote;
tvalue[plen + 2] = '\0';

This logic doesn't appear in the JUNOS driver (/usr/libexec/ui/cscript).
I'll open a PR for this.

There is a limitation in XSLT that one can't mix strings with both
single and double quotes.  Strange but true.

Thanks,
 Phil
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] Is it possible to pass apostrophe character(ASCII dec code 39) as an argument value to SLAX script?

2018-07-12 Thread Martin T
On Thu, Jul 12, 2018 at 11:20 PM Phil Shafer  wrote:
>
> Martin T writes:
> >Is it possible to pass apostrophe character(ASCII dec code 39) as an
> >argument value to SLAX script? I have tried to escape it, but it does
> >not seem to work:
>
> Quote it:
>
> version 1.2;
>
> param $char = "-";
>
> main  {
>  "got: " _ $char;
> }
>
> root@box> op apos char "`"
> got: `
>
> root@box>
>
> Thanks,
>  Phil

Phil,

aren't you using grave accent("echo -e "\x60"") character? I was using
"echo -e "\x27"" character.


thanks,
Martin
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] Is it possible to pass apostrophe character(ASCII dec code 39) as an argument value to SLAX script?

2018-07-12 Thread Phil Shafer
Martin T writes:
>Is it possible to pass apostrophe character(ASCII dec code 39) as an
>argument value to SLAX script? I have tried to escape it, but it does
>not seem to work:

Quote it:

version 1.2;

param $char = "-";

main  {
 "got: " _ $char;
}

root@box> op apos char "`"
got: `

root@box>

Thanks,
 Phil
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] Is it possible to pass apostrophe character(ASCII dec code 39) as an argument value to SLAX script?

2018-07-12 Thread Nathan Ward
I thought I had it by being cunning, but, no!

{master}
nward@mx> op test chr \x27
''':(null):(2) Invalid expression
error: runtime error
error: Evaluating user parameter chr failed

{master}
nward@mx> op test chr \\x27
'\'':(null):(3) Invalid expression
error: runtime error
error: Evaluating user parameter chr failed

:-(

> On 12/07/2018, at 8:00 PM, Martin T  wrote:
> 
> Hi!
> 
> Is it possible to pass apostrophe character(ASCII dec code 39) as an
> argument value to SLAX script? I have tried to escape it, but it does
> not seem to work:
> 
> root@vmx1> op test chr '
> ''':(null):(2) Invalid expression
> error: runtime error
> error: Evaluating user parameter chr failed
> 
> root@vmx1> op test chr "'"
> ''':(null):(2) Invalid expression
> error: runtime error
> error: Evaluating user parameter chr failed
> 
> root@vmx1> op test chr \'
> '\'':(null):(3) Invalid expression
> error: runtime error
> error: Evaluating user parameter chr failed
> 
> root@vmx1> op test chr '''
> ':(null):(2) Invalid expression
> error: runtime error
> error: Evaluating user parameter chr failed
> 
> root@vmx1>
> 
> 
> Script named test is following:
> 
> root@vmx1> file show /var/db/scripts/op/test.slax
> version 1.1;
> 
> ns junos = "http://xml.juniper.net/junos/*/junos;;
> ns xnm = "http://xml.juniper.net/xnm/1.1/xnm;;
> ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0;;
> 
> import "../import/junos.xsl";
> 
> var $arguments = {
> {
> "chr";
>}
> }
> 
> param $chr;
> 
> match / {
> {
> "Character: " _ "'" _ $chr _ "'";
>}
> }
> 
> root@vmx1>
> 
> I guess it is not possible and one needs to use get-input() function?
> 
> 
> thanks,
> Martin
> ___
> juniper-nsp mailing list juniper-nsp@puck.nether.net
> https://puck.nether.net/mailman/listinfo/juniper-nsp

___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp