[cli] allow to escape separators (#4608)

This commit is contained in:
Eduardo Montoya
2020-03-02 08:48:31 -08:00
committed by GitHub
parent f4775fe13a
commit 15f6808206
5 changed files with 74 additions and 18 deletions
+17 -2
View File
@@ -626,6 +626,20 @@ class OpenThread(IThci):
print('%s call getCommissionerSessionId' % self.port)
return self.__sendCommand('commissioner sessionid')[0]
def __escapeEscapable(self, string):
"""Escape CLI escapable characters in the given string.
Args:
string (str): UTF-8 input string.
Returns:
[str]: The modified string with escaped characters.
"""
escapable_chars = '\\ \t\r\n'
for char in escapable_chars:
string = string.replace(char, '\\%s' % char)
return string
def _connect(self):
print('My port is %s' % self.port)
if self.port.startswith('COM'):
@@ -688,6 +702,7 @@ class OpenThread(IThci):
"""
print('%s call setNetworkName' % self.port)
print(networkName)
networkName = self.__escapeEscapable(networkName)
try:
cmd = 'networkname %s' % networkName
datasetCmd = 'dataset networkname %s' % networkName
@@ -2393,7 +2408,7 @@ class OpenThread(IThci):
if sNetworkName is not None:
cmd += ' networkname '
cmd += str(sNetworkName)
cmd += self.__escapeEscapable(str(sNetworkName))
if xChannel is not None:
cmd += ' channel '
@@ -2594,7 +2609,7 @@ class OpenThread(IThci):
if sNetworkName is not None:
cmd += ' networkname '
cmd += str(sNetworkName)
cmd += self.__escapeEscapable(str(sNetworkName))
if xCommissionerSessionId is not None:
cmd += ' binary '