diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2024-05-15 17:45:16 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2024-05-16 10:13:55 +0200 |
commit | 5ae1379fcdd00228e683ae90991e275f570cd92d (patch) | |
tree | 07f85767ebb89b1419dacafd4f37844274fa3f02 /sw | |
parent | d74fb6b571304b41c13b7a6dcdd2b853bfca7210 (diff) |
writerfilter: fix parsing of invalid STYLEREF field
forum-mso-en-3309.docx contains a funny field that doesn't follow
the grammar in the OOXML spec:
STYLEREF \t "Heading 1" \* MERGEFORMAT
Word can evaluate it and find the paragraph, so make the parser a bit
more flexible, by adding known switches that don't have arguments, so
that any argument following these becomes a field argument,
for now only for STYLEREF.
(regression from commit d4fdafa103bfea94a279d7069ddc50ba92f67d01)
Change-Id: Ic42cd2be58fd65a817946e21a9661d357b02a99a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167697
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index bdf05bee33a5..0d6570997e82 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -5457,13 +5457,27 @@ std::tuple<OUString, std::vector<OUString>, std::vector<OUString> > splitFieldCo OUString const token = lcl_ExtractToken(rCommand, nStartIndex, bHaveToken, bIsSwitch); assert(nStartIndex <= rCommand.size()); + static std::map<OUString, std::set<OUString>> const noArgumentSwitches = { + { u"STYLEREF"_ustr, + { u"\\l"_ustr, u"\\n"_ustr, u"\\p"_ustr, u"\\r"_ustr, u"\\t"_ustr, u"\\w"_ustr } } + }; if (bHaveToken) { if (sType.isEmpty()) { sType = token.toAsciiUpperCase(); } - else if (bIsSwitch || !switches.empty()) + else if (bIsSwitch) + { + switches.push_back(token); + } + // evidently Word evaluates 'STYLEREF \t "Heading 1" \* MERGEFORMAT' + // despite the grammar specifying that the style name must + // precede switches like '\t'; try to approximate that here + // by checking for known switches that don't expect arguments + else if (auto const it = noArgumentSwitches.find(sType); + !switches.empty() && (it == noArgumentSwitches.end() + || it->second.find(switches.back().toAsciiLowerCase()) == it->second.end())) { switches.push_back(token); } |