Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A parameter type that takes an "equals" does not work. #2

Open
Firstyear opened this issue Jan 8, 2017 · 3 comments
Open

A parameter type that takes an "equals" does not work. #2

Firstyear opened this issue Jan 8, 2017 · 3 comments

Comments

@Firstyear
Copy link

I have the following code.

def ui_command_test(self, ldapurl, binddn):
    print(ldapurl)
    print(binddn)

Given this command line:

/> help test

SYNTAX
======
test ldapurl binddn 

/> test ldapurl=ldap://localhost binddn="cn=Directory Manager"
ldap://localhost


Note the "blank" output for binddn. This is due to the quoting of the value.

If we remove the quotes

/> test ldapurl=ldap://localhost binddn=cn=Directory Manager
ldap://localhost
cn

The final = is then turned into another parameter, and we drop part of the value.

Additionally, escaping does not function.

/> test ldapurl=ldap://localhost binddn=cn\=Directory Manager
ldap://localhost
cn\

So this doesn't help either.

It would be great if values could be quoted, and the internal content of the quotes taken as a whole string regardless of whitespace or char presence until the next matching quote.

@Firstyear
Copy link
Author

--- /usr/lib/python3.5/site-packages/configshell_fb/shell.py	2016-04-08 09:57:03.000000000 +1000
+++ /root/shell.py	2017-01-08 13:12:16.338644935 +1000
@@ -19,7 +19,7 @@
 import six
 import sys
 from pyparsing import (alphanums, Empty, Group, OneOrMore, Optional,
-                       ParseResults, Regex, Suppress, Word)
+                       ParseResults, Regex, Suppress, Word, QuotedString, Or)
 
 from . import console
 from . import log
@@ -107,11 +107,12 @@
 
         # Grammar of the command line
         command = locatedExpr(Word(alphanums + '_'))('command')
-        var = Word(alphanums + '_\+/.<>()~@:-%[]')
-        value = var
+        var = Word(alphanums + '_\+/.<>()~@:-%[]=')
+        qvar = QuotedString('"', unquoteResults=True)
+        value = Or([qvar, var])
         keyword = Word(alphanums + '_\-')
         kparam = locatedExpr(keyword + Suppress('=') + Optional(value, default=''))('kparams*')
-        pparam = locatedExpr(var)('pparams*')
+        pparam = locatedExpr(value)('pparams*')
         parameter = kparam | pparam
         parameters = OneOrMore(parameter)
         bookmark = Regex('@([A-Za-z0-9:_.]|-)+')

This patch resolves the issue.

@Firstyear
Copy link
Author

Firstyear commented Jan 8, 2017

/> test a b
a
b
/> test "a" "b"
a
b
/> test "a" b
a
b
/> test ldapurl=ldap://localhost binddn="cn=Directory Manager"
ldap://localhost
cn=Directory Manager


@pawelkax
Copy link

Hi All,
I created pull request with changes proposed in this issue.
Link to it: 4dba479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants