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

Double quotation mark will miss or become single quotation mark. #1

Open
thejimmylin opened this issue Jul 23, 2020 · 1 comment
Open
Labels
invalid This doesn't seem right

Comments

@thejimmylin
Copy link
Owner

Case1

set dstintf "port1"

set dstintf port1

Case2

set poolname "ippool jimmylin 168.100.168.11"

set poolname 'ippool jimmylin 168.100.168.11'
@thejimmylin
Copy link
Owner Author

thejimmylin commented Jul 24, 2020

There are three kind of split

  1. string.split(' ')
  2. shlex.split(string)
  3. shlex.split(string, posix=False)

And two kind of join

  1. ' '.join(strings)
  2. shlex.join(strings)

Test1 - split

>>> import shlex
>>> s = 'set service HTTP "HTTPS" "service abc def" \'abc\''
  1. string.split(' ') - Can't recognize word in quotes.
>>> s.split(' ')
['set', 'service', 'HTTP', '"HTTPS"', '"service', 'abc', 'def"', "'abc'"]
  1. shlex.split(string) - Some quotes disapear.
>>> shlex.split(string)
['set', 'service', 'HTTP', 'HTTPS', 'service abc def', 'abc']
  1. shlex.split(string, pox=False) - Perfect!
>>> shlex.split(string, posix=False)
['set', 'service', 'HTTP', '"HTTPS"', '"service abc def"', "'abc'"]

Test2 - join

Use shlex.split(string, posix=False) for the test about join.

  1. ' '.join(strings) - Prefect
>>> ' '.join(shlex.split(string, posix=False))
'set service HTTP "HTTPS" "service abc def" \'abc\''
  1. shlex.join(strings) - Too many quotes added.
>>> shlex.join(shlex.split(string, posix=False))
'set service HTTP \'"HTTPS"\' \'"service abc def"\' \'\'"\'"\'abc\'"\'"\'\''

Conclusion

Use
shlex.split(string, posix=False)

and
' '.join(strings)

@thejimmylin thejimmylin added bug Something isn't working invalid This doesn't seem right and removed bug Something isn't working labels Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant