File Metadata

Author
cullmann
Created
Mar 5 2019, 7:09 PM

test.diff

diff --git a/autotests/input/syntax/brokenlang.xml b/autotests/input/syntax/brokenlang.xml
new file mode 100644
index 0000000..0cd9e3f
--- /dev/null
+++ b/autotests/input/syntax/brokenlang.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE language SYSTEM "language.dtd">
+<language name="Broken Syntax" section="Others" version="1" kateversion="5.0">
+ <highlighting>
+ <list name="keywords"
+ fier />
+ </context>
+ </contexts>
+
+ <itemDatas>
+ <itemData name="Normal Text" defStyleNum="dsNormal" />
+ <iteng>
+ <general>
+ <keywl
+</language>
diff --git a/autotests/syntaxrepository_test.cpp b/autotests/syntaxrepository_test.cpp
index 2c4b2a0..082ec27 100644
--- a/autotests/syntaxrepository_test.cpp
+++ b/autotests/syntaxrepository_test.cpp
@@ -158,7 +158,7 @@ private Q_SLOTS:
State initialState;
hl.setDefinition(def);
const auto state = hl.highlightLine(QLatin1String("This should not crash } ] ) !"), initialState);
- QVERIFY(!def.isValid() || state != initialState);
+ QVERIFY(!def.isValid() || state != initialState || def.name() == QLatin1String("Broken Syntax"));
}
}
@@ -310,7 +310,7 @@ private Q_SLOTS:
formatIds.insert(format.id());
}
}
- QVERIFY(!def.isValid() || !formatIds.isEmpty());
+ QVERIFY(!def.isValid() || def.name() == QLatin1String("Broken Syntax") || !formatIds.isEmpty());
// ensure all ids are there from 1..size
for (int i = 1; i <= formatIds.size(); ++i) {
diff --git a/autotests/test-config.h.in b/autotests/test-config.h.in
index 15e1006..c2874d1 100644
--- a/autotests/test-config.h.in
+++ b/autotests/test-config.h.in
@@ -41,9 +41,11 @@
*/
void initRepositorySearchPaths(KSyntaxHighlighting::Repository &repository)
{
-#ifdef HAS_SYNTAX_RESOURCE
- Q_UNUSED(repository)
-#else
+ // add extra search path for e.g. broken highlighting test
+ repository.addCustomSearchPath(QStringLiteral(TESTSRCDIR "/input"));
+
+ // handle no-resources case
+#ifndef HAS_SYNTAX_RESOURCE
repository.addCustomSearchPath(QStringLiteral("@CMAKE_SOURCE_DIR@/data"));
repository.addCustomSearchPath(QStringLiteral("@CMAKE_BINARY_DIR@/data/generated"));
#endif
diff --git a/src/lib/abstracthighlighter.cpp b/src/lib/abstracthighlighter.cpp
index a03cf6b..159fb52 100644
--- a/src/lib/abstracthighlighter.cpp
+++ b/src/lib/abstracthighlighter.cpp
@@ -118,13 +118,13 @@ State AbstractHighlighter::highlightLine(const QString& text, const State &state
// verify definition, deal with no highlighting being enabled
d->ensureDefinitionLoaded();
- if (!d->m_definition.isValid()) {
+ const auto defData = DefinitionData::get(d->m_definition);
+ if (!d->m_definition.isValid() || !defData->isLoaded()) {
applyFormat(0, text.size(), Format());
return State();
}
// verify/initialize state
- auto defData = DefinitionData::get(d->m_definition);
auto newState = state;
auto stateData = StateData::get(newState);
const DefinitionRef currentDefRef(d->m_definition);