diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-08-27 10:06:59 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-08-27 16:09:36 +0200 |
commit | 69c501b7d7d3df1c6dbc835a8d71b4e1077ec40d (patch) | |
tree | e4a4afb35c7f5977f6a5aa55dc074391e1a7a737 /sc | |
parent | 6bdc0849ddf802ccc9be9a9ae9cc31812d64ac91 (diff) |
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
(cherry picked from commit 45c7bb44b4d76a387dbb0dc6b10e353440cb3923)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172413
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/filter/html/data/bad-json.html | 4 | ||||
-rw-r--r-- | sc/qa/filter/html/html.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/html/htmlpars.cxx | 10 |
3 files changed, 28 insertions, 1 deletions
diff --git a/sc/qa/filter/html/data/bad-json.html b/sc/qa/filter/html/data/bad-json.html new file mode 100644 index 000000000000..3a978e777f6d --- /dev/null +++ b/sc/qa/filter/html/data/bad-json.html @@ -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> diff --git a/sc/qa/filter/html/html.cxx b/sc/qa/filter/html/html.cxx index 38b0500297ba..9e60af2565f9 100644 --- a/sc/qa/filter/html/html.cxx +++ b/sc/qa/filter/html/html.cxx @@ -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: diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index fdbca6056c92..50b58bb9471e 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -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()) |