Kaydet (Commit) e4d5b5ef authored tarafından Mike Kaganski's avatar Mike Kaganski Kaydeden (comit) Miklos Vajna

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/20435Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst c321b618
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment