writerfilter/qa/cppunittests/misc/misc.cxx | 20 ++++++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 18 +++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-)
New commits: commit e4d5b5efac71ed2a08dcd09877078a6cf6bde0d2 Author: Mike Kaganski <mike.kagan...@collabora.com> Date: Mon Dec 7 23:00:32 2015 +1000 tdf#54584: adjust skip-slash condition, allow unterminated quote Experimenting with different non-alpha characters in front of field, most of them aren't allowed and result in field not recognized by MS Word: #$%&'()*+,-./:;<>?@[]^_`{|}~ Besides, if backslash "\" is followed by another backslash or space, it is illegal, too. This patch takes care of it. On the other side, not closing quotes is allowed by MS Word. This patch allows this, too. The patch does not handle another allowed field code "=2+2". This should be done in another commit. Change-Id: I842fe59c026b68977e61a7ae0b5495c02803ad83 Reviewed-on: https://gerrit.libreoffice.org/20435 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/writerfilter/qa/cppunittests/misc/misc.cxx b/writerfilter/qa/cppunittests/misc/misc.cxx index 49e5e1b..522dc19 100644 --- a/writerfilter/qa/cppunittests/misc/misc.cxx +++ b/writerfilter/qa/cppunittests/misc/misc.cxx @@ -160,6 +160,26 @@ void WriterfilterMiscTest::testFieldParameters() CPPUNIT_ASSERT_EQUAL(OUString("foobar"), boost::get<2>(result)[1]); CPPUNIT_ASSERT_EQUAL(OUString("\\A"), boost::get<2>(result)[2]); CPPUNIT_ASSERT_EQUAL(OUString(), boost::get<2>(result)[3]); + + for (auto prefix : {"#", "$", "%", "&", "'", "(", ")", "*", "+", ",", + "-", ".", "/", ":", ";", "<", ">", "?", "@", "[", + "]", "^", "_", "`", "{", "|", "}", "~"}) + { + OUString test(OUString::createFromAscii(prefix) + OUString("PAGE")); + result = lcl_SplitFieldCommand(test + OUString(" ")); + CPPUNIT_ASSERT_EQUAL(test, boost::get<0>(result)); + } + result = lcl_SplitFieldCommand("\\PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), boost::get<0>(result)); + result = lcl_SplitFieldCommand("\\ PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("\\ "), boost::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), boost::get<1>(result)[0]); + result = lcl_SplitFieldCommand("\\\\PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("\\PAGE"), boost::get<0>(result)); + result = lcl_SplitFieldCommand("\"PAGE\" "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), boost::get<0>(result)); + result = lcl_SplitFieldCommand("\"PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE "), boost::get<0>(result)); } CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 8e079ea..ec4304b 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -2274,15 +2274,12 @@ static OUString lcl_ExtractToken(OUString const& rCommand, assert(rIndex == rCommand.getLength()); if (bQuoted) { + // MS Word allows this, so just emit a debug message SAL_INFO("writerfilter.dmapper", "field argument with unterminated quote"); - return OUString(); - } - else - { - rHaveToken = !token.isEmpty(); - return token.makeStringAndClear(); } + rHaveToken = !token.isEmpty(); + return token.makeStringAndClear(); } boost::tuple<OUString, std::vector<OUString>, std::vector<OUString> > @@ -2292,10 +2289,13 @@ lcl_SplitFieldCommand(const OUString& rCommand) std::vector<OUString> arguments; std::vector<OUString> switches; sal_Int32 nStartIndex(0); - // tdf#54584: Field may be prepended by a backslash - skip it + // tdf#54584: Field may be prepended by a backslash + // This is not an escapement, but already escaped literal "\" + // MS Word allows this, so just skip it if ((rCommand.getLength() >= nStartIndex + 2) && - (rCommand[nStartIndex] == '\\') && - (rCommand[nStartIndex + 1] != '\\')) + (rCommand[nStartIndex] == L'\\') && + (rCommand[nStartIndex + 1] != L'\\') && + (rCommand[nStartIndex + 1] != L' ')) { ++nStartIndex; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits