diff --git a/autotests/input/syntax/brokenlang.xml b/autotests/input/syntax/brokenlang.xml new file mode 100644 --- /dev/null +++ b/autotests/input/syntax/brokenlang.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/autotests/syntaxrepository_test.cpp b/autotests/syntaxrepository_test.cpp --- a/autotests/syntaxrepository_test.cpp +++ b/autotests/syntaxrepository_test.cpp @@ -158,7 +158,7 @@ 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 @@ 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 --- 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 --- a/src/lib/abstracthighlighter.cpp +++ b/src/lib/abstracthighlighter.cpp @@ -118,13 +118,13 @@ // 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); diff --git a/src/lib/definition.cpp b/src/lib/definition.cpp --- a/src/lib/definition.cpp +++ b/src/lib/definition.cpp @@ -320,8 +320,11 @@ Context* DefinitionData::initialContext() const { - Q_ASSERT(!contexts.isEmpty()); - return contexts.first(); + Context* c = nullptr; + if (!contexts.isEmpty()) { + c = contexts.first(); + } + return c; } Context* DefinitionData::contextByName(const QString& wantedName) const