tdf#162574 sc HTML paste: handle not well-formed json for td data-sheets-value
Regression from commit f5f6db55a5938f37a1c136be904ad7f10a3438ef (tdf#159483 sc HTML paste: handle data-sheets-value here, too, 2024-02-08), in case the HTML markup is like: <td data-sheets-value="... garbage ..."> then just ignore it, as if the attribute would be missing. We're only interested in the case where it contains well-formed JSON. Change-Id: Id625205e56ae2bfe05a26296a1a0f3abf6d5a4f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172452 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><table>
|
||||
<tbody>
|
||||
<tr><td data-sheets-value="{"></td></tr>
|
||||
</tbody></table></div>
|
||||
@@ -85,6 +85,21 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteTdAsText)
|
||||
CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, eCellType);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testPasteBadJson)
|
||||
{
|
||||
createScDoc();
|
||||
|
||||
// Just care we don't crash on not-well-formed JSON:
|
||||
ScDocument* pDoc = getScDoc();
|
||||
ScAddress aCellPos(/*nColP=*/0, /*nRowP=*/0, /*nTabP=*/0);
|
||||
ScImportExport aImporter(*pDoc, aCellPos);
|
||||
SvFileStream aFile(createFileURL(u"bad-json.html"), StreamMode::READ);
|
||||
SvMemoryStream aMemory;
|
||||
aMemory.WriteStream(aFile);
|
||||
aMemory.Seek(0);
|
||||
CPPUNIT_ASSERT(aImporter.ImportStream(aMemory, OUString(), SotClipboardFormatId::HTML));
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testPasteTdAsBools)
|
||||
{
|
||||
// Given an empty document:
|
||||
|
||||
@@ -84,7 +84,15 @@ void ParseDataSheetsValue(const OUString& rDataSheetsValue, std::optional<OUStri
|
||||
const char* pEncodedOption = aEncodedOption.getStr();
|
||||
std::stringstream aStream(pEncodedOption);
|
||||
boost::property_tree::ptree aTree;
|
||||
boost::property_tree::read_json(aStream, aTree);
|
||||
try
|
||||
{
|
||||
boost::property_tree::read_json(aStream, aTree);
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
SAL_WARN("sc", "ParseDataSheetsValue: not well-formed json");
|
||||
return;
|
||||
}
|
||||
// The "1" key describes the original data type.
|
||||
auto it = aTree.find("1");
|
||||
if (it != aTree.not_found())
|
||||
|
||||
Reference in New Issue
Block a user