WML: fix infinite loop in contexts switch & only highlight tags with valid names

Authored by nibags on Jan 3 2019, 7:31 PM.

Description

WML: fix infinite loop in contexts switch & only highlight tags with valid names

Summary:
BUG: 402720

In the wml.xml file an infinite context switch between section and error is generated, through lineEndContext: in a line break, the section context sends to error and then this is #poped in the line break, causing an infinite cycle. This causes that Kate freezes.

This is reproducible by typing the [ character and then a line break.

This bug is reproducible only in KSyntaxHighlighting, since in KF5.48 there is no problem. It's probably necessary to add a guard that avoids infinite context changes.

Also, the WML highlighter is a little old and I have seen some problems in sample files. The highlighter considers all content between [ and ] as tag. According to the documentation [1]:

Also, tag and key names follow a special format. They will contain only alphanumeric characters and underscores; in particular, they will not contain +, -, or whitespace.

Considering this, and based on the VSCode highlighter, I modified the code so that only tags with valid names are highlighted.

References:

Reviewers: Framework: Syntax Highlighting, dhaumann, cullmann

Reviewed By: Framework: Syntax Highlighting, dhaumann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: Kate, Frameworks

Differential Revision: https://phabricator.kde.org/D17891