Bug 402720 - Kate hangs when trying to highlight some Wesnoth configuration files
Summary: Kate hangs when trying to highlight some Wesnoth configuration files
Status: RESOLVED FIXED
Alias: None
Product: frameworks-syntax-highlighting
Classification: Frameworks and Libraries
Component: syntax (show other bugs)
Version: 5.52.0
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-31 00:47 UTC by Edward Chernenko
Modified: 2019-01-03 19:49 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.54.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edward Chernenko 2018-12-31 00:47:42 UTC
SUMMARY

The following file causes Kate to hang when syntax highlighting is enabled:
https://github.com/wesnoth/wesnoth/blob/66c07530000e72636b50579a4b2999570c85eb8e/data/gui/window/tooltip_floating.cfg

Used highlighting mode: Wesnoth Markup Language (wml.xml)

It also hangs when you try to type "[" symbol while in "Wesnoth Markup Language" mode.

STEPS TO REPRODUCE
1. Open [tooltip_floating.cfg] (see above) in Kate.
2. If "Wesnoth Markup Language" highlighting wasn't selected (*.cfg is also used for Nagios), select it.

OR

1. Open new (blank) file in Kate.
2. Select "Wesnoth Markup Language" highlighting.
3. Type "[" symbol.

OBSERVED RESULT

Kate hangs.

EXPECTED RESULT

Kate highlights.

SOFTWARE/OS VERSIONS
Windows: N/A
MacOS: N/A
Linux/KDE Plasma: N/A
KDE Plasma Version: 5.52.0
KDE Frameworks Version: 5
Qt Version: 5.11.1

ADDITIONAL INFORMATION
Comment 1 Nibaldo G. 2018-12-31 09:24:10 UTC
From what I see, an infinite loop occurs when switching the context between "section" and "error"
Comment 2 Nibaldo G. 2018-12-31 20:06:12 UTC
Proposed patch: https://phabricator.kde.org/D17891
Comment 3 Dominik Haumann 2019-01-03 19:35:16 UTC
Git commit c276c7003d3569001b12e8095e896da88f13413e by Dominik Haumann, on behalf of Nibaldo González.
Committed on 03/01/2019 at 19:35.
Pushed by dhaumann into branch 'master'.

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

Summary:

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:**
* [1] Wesnoth Wiki. SyntaxWML, Tag and Attribute Structures: https://wiki.wesnoth.org/SyntaxWML#Tag_and_Attribute_Structures
* [2] Wesnoth Markup Language syntax highlightning for VS Code: https://github.com/Byteron/wml , https://marketplace.visualstudio.com/items?itemName=Bitron.wml

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

A  +101  -0    autotests/folding/test.pbl.fold
A  +108  -0    autotests/html/test.pbl.html
A  +101  -0    autotests/input/test.pbl
A  +101  -0    autotests/reference/test.pbl.ref
M  +14   -10   data/syntax/wml.xml

https://commits.kde.org/syntax-highlighting/c276c7003d3569001b12e8095e896da88f13413e