Correction on comment-detection regexp
authorLertsenem <lertsenem@lertsenem.com>
Wed, 12 Oct 2016 21:54:04 +0000 (23:54 +0200)
committerLertsenem <lertsenem@lertsenem.com>
Wed, 12 Oct 2016 21:54:04 +0000 (23:54 +0200)
During the config parse, comments are removed using a complex regexp,
matching (among other things) '//'. A problem arises when your
configuration contains a link of some sort (such as 'http://' ...). The
regexp then consider the '//' and what follows as a comment (and your
configuration is consequently considered corrupt).

Escapinf the '/' works for a time, but it fails as soon as you use the
'config' command at runtime, because the configuration is then
rewritten.

Therefore I changed the regexp used to match comments. It's a fairly
complex regexp though, and I'm not 100% positive my change is perfect.
Fell free to review it.

rainbowstream/colorset/config
rainbowstream/config.py

index 6bfd43e6358488a8f50dc792149fd3008a3b725b..54b76ff055b8af68deaf410c630e4198c2fcc9c7 100644 (file)
@@ -24,7 +24,7 @@
     // 'conversation': max tweet in a thread
     "CONVERSATION_MAX" : 30,
     // 'quote' format
-    "QUOTE_FORMAT" : "#comment https:\/\/twitter.com\/#owner\/status\/#tid",
+    "QUOTE_FORMAT" : "#comment https://twitter.com/#owner/status/#tid",
     // 'thread' meta format
     "THREAD_META_LEFT" : "(#id) #clock",
     "THREAD_META_RIGHT" : "#clock (#id)",
index 1573cce1f9a14ea184750469e577ae96ef72c412..5f5b81bd18fe67f23339fe631e6e7b9b3e6b25ea 100644 (file)
@@ -6,7 +6,7 @@ from collections import OrderedDict
 
 # Regular expression for comments in config file
 comment_re = re.compile(
-    '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
+    '(^)[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
     re.DOTALL | re.MULTILINE
 )