[Asterisk-code-review] astconfigparser: Allow escaped semicolons. (testsuite[master])

Joshua Colp asteriskteam at digium.com
Sat Jul 16 13:15:18 CDT 2016


Joshua Colp has uploaded a new change for review.

  https://gerrit.asterisk.org/3214

Change subject: astconfigparser: Allow escaped semicolons.
......................................................................

astconfigparser: Allow escaped semicolons.

When configuring SIP URIs in the pjsip.conf file it is
necessary to escape the semicolon so the parser does not
treat it as a comment. This change allows this to work in
the astconfigparser implementation.

A secondary bug where some data was lost if a configuration
option included a "=" in its value was also fixed.

Change-Id: Ibff2af1c0c4bce28b94360aecec5996f363b4ae8
---
M lib/python/asterisk/astconfigparser.py
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/14/3214/1

diff --git a/lib/python/asterisk/astconfigparser.py b/lib/python/asterisk/astconfigparser.py
index 778b17f..0e1b0f8 100644
--- a/lib/python/asterisk/astconfigparser.py
+++ b/lib/python/asterisk/astconfigparser.py
@@ -191,9 +191,15 @@
         # otherwise it was an embedded comment so combine
         return ''.join([part[0].strip(), ' ', line]).rstrip(), False
 
-    # check for eol comment
-    return line.partition(COMMENT)[0].strip(), False
+    # find the first occurence of a comment that is not escaped
+    match = re.match(r'(?<!\\)(?:\\\\)*;', line)
 
+    if match:
+         # the end of where the real string is is where the escaped part is
+         end = match.start()
+         line = line[0:end]
+
+    return line.strip(), False
 
 def try_include(line):
     """
@@ -231,7 +237,7 @@
 
 def try_option(line):
     """Parses the line as an option, returning the key/value pair."""
-    data = re.split('=>?', line)
+    data = re.split('=>?', line, 1)
     # should split in two (key/val), but either way use first two elements
     return data[0].rstrip(), data[1].lstrip()
 

-- 
To view, visit https://gerrit.asterisk.org/3214
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibff2af1c0c4bce28b94360aecec5996f363b4ae8
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list