Python Forum

Full Version: Weird Python tags syntax coloring bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Take a look at this:
filename != "" and foldername != ""
Note that the close string appears to be interpreted as an open.

Saw it less simplified at https://python-forum.io/Thread-Help-with...ion-issues
filename != "" and foldername != ""
filename != """""" and foldername != """"""
filename != '' and foldername != ''
filename != '''''' and foldername != ''''''
Interestingly, it works fine for triple quoted strings.
Issue presents with both single and double quotes.
interesting....Im surprised we caught that so late in the process of seeing code in syntax highlighter for awhile now.

Wondering if it only occurs on empty strings
py tags
filename != "" and foldername != ""
code tags
filename != "" and foldername != ""
---

py tags
filename != " " and foldername != " "
code tags
filename != " " and foldername != " "
filename != """and foldername != """
EDIT:
yup so its interpreting it as
Quote:filename != (")(" and foldername != ")(")
odd
ok so i re-found the post where i show the code
https://python-forum.io/Thread-syntax-hi...d=79#pid79

it appears that it handles that via regex....and i suck at regex. Anyone want to take a whack at it for figuring out where this regex for strings would cause this problem?
Quote:
        this.regexList = [
                { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
                { regex: /^\s*@\w+/gm,                                      css: 'decorator' },
                { regex: /(['\"]{3})([^\1])*?\1/gm,                         css: 'comments' },
                { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm,                  css: 'string' },
                { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm,                css: 'string' },
                { regex: /\+|\-|\*|\/|\%|=|==/gm,                           css: 'keyword' },
                { regex: /\b\d+\.?\w*/g,                                    css: 'value' },
                { regex: new RegExp(this.getKeywords(funcs), 'gmi'),        css: 'functions' },
                { regex: new RegExp(this.getKeywords(keywords), 'gm'),      css: 'keyword' },
                { regex: new RegExp(this.getKeywords(special), 'gm'),       css: 'color1' }
                ];
(Jun-02-2017, 01:49 AM)metulburr Wrote: [ -> ]              { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm,                  css: 'string' },
              { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm,                css: 'string' },


Playing around in regexpal makes me think the negative lookahead can either just be removed, or be made optional.  ie: the beginning of the regex should change from /"(?!") to /"(?!")? (note the trailing question mark). But testing with more strings would be pretty much required to make sure it'll still parse as expected.