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

Parameter parsing - unexpected behavior #242

Closed
bitprophet opened this Issue Aug 19, 2011 · 4 comments

Comments

Projects
None yet
1 participant
@bitprophet
Member

bitprophet commented Aug 19, 2011

Description

When using empty strings in named parameters, it seems that the parameters are being parsed incorrectly.

For example:

def test(foo, bar="Nothing", baz="Bazy"):
    print "foo: %s" % foo
    print "bar: %s" % bar
    print "baz: %s" % baz

Run:

> fab test:1,'',baz=''
foo: 1
bar: 
baz: baz

Done.

More test cases here: http://gist.github.com/615785


Originally submitted by Aaron Levy (aaronlevy) on 2010-10-07 at 04:29pm EDT


Closed as Done on 2010-11-12 at 01:43pm EST

@ghost ghost assigned bitprophet Aug 19, 2011

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

Member

Aaron Levy (aaronlevy) posted:


Better codeblock:

def test(foo, bar="Nothing", baz="Bazy"):
    print "foo: %s" % foo
    print "bar: %s" % bar
    print "baz: %s" % baz
> fab test:1,'',baz=''
foo: 1
bar: 
baz: baz

Done.

on 2010-10-07 at 04:31pm EDT

Member

bitprophet commented Aug 19, 2011

Aaron Levy (aaronlevy) posted:


Better codeblock:

def test(foo, bar="Nothing", baz="Bazy"):
    print "foo: %s" % foo
    print "bar: %s" % bar
    print "baz: %s" % baz
> fab test:1,'',baz=''
foo: 1
bar: 
baz: baz

Done.

on 2010-10-07 at 04:31pm EDT

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

Member

Aaron Levy (aaronlevy) posted:


Potential fix for the issue below. In cases where a parameter is foo='' the code currently tests "if v:" in the k/v pair. If not, it uses the key as an arg. However, by testing for the existence of the separator (=) instead, it uses the correct: kwargs[foo] = ''.

diff --git a/fabric/main.py b/fabric/main.py
index 8307a88..4c300b5 100644
--- a/fabric/main.py
+++ b/fabric/main.py
@@ -239,7 +239,7 @@ def parse_arguments(arguments):
             cmd, argstr = cmd.split(':', 1)
             for pair in argstr.split(','):
                 k, _, v = pair.partition('=')
-                if v:
+                if _:
                     # Catch, interpret host/hosts/role/roles kwargs
                     if k in ['host', 'hosts', 'role', 'roles']:
                         if k == 'host':


on 2010-10-07 at 05:17pm EDT

Member

bitprophet commented Aug 19, 2011

Aaron Levy (aaronlevy) posted:


Potential fix for the issue below. In cases where a parameter is foo='' the code currently tests "if v:" in the k/v pair. If not, it uses the key as an arg. However, by testing for the existence of the separator (=) instead, it uses the correct: kwargs[foo] = ''.

diff --git a/fabric/main.py b/fabric/main.py
index 8307a88..4c300b5 100644
--- a/fabric/main.py
+++ b/fabric/main.py
@@ -239,7 +239,7 @@ def parse_arguments(arguments):
             cmd, argstr = cmd.split(':', 1)
             for pair in argstr.split(','):
                 k, _, v = pair.partition('=')
-                if v:
+                if _:
                     # Catch, interpret host/hosts/role/roles kwargs
                     if k in ['host', 'hosts', 'role', 'roles']:
                         if k == 'host':


on 2010-10-07 at 05:17pm EDT

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

Member

Aaron Levy (aaronlevy) posted:


This is against 0.9.0


on 2010-10-07 at 05:18pm EDT

Member

bitprophet commented Aug 19, 2011

Aaron Levy (aaronlevy) posted:


This is against 0.9.0


on 2010-10-07 at 05:18pm EDT

@bitprophet

This comment has been minimized.

Show comment
Hide comment
@bitprophet

bitprophet Aug 19, 2011

Member

Jeff Forcier (bitprophet) posted:


Applied in changeset commit:fca09e660f40bedbe23d61f088417251632943c0.


on 2010-11-12 at 01:43pm EST

Member

bitprophet commented Aug 19, 2011

Jeff Forcier (bitprophet) posted:


Applied in changeset commit:fca09e660f40bedbe23d61f088417251632943c0.


on 2010-11-12 at 01:43pm EST

@bitprophet bitprophet closed this Aug 19, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment