Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The release run heads these entries with the version and opens a fresh

## Unreleased

- Document HTML escapes locale metadata and keeps individual views for sheets,
slides and pages named `document`.

- Archive listings reserve shipped script and stylesheet paths before exposing
entries, and reject unsafe entry links. Archives cannot replace viewer scripts.

Expand Down
12 changes: 7 additions & 5 deletions src/odr/internal/html/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <odr/internal/html/style_registry.hpp>
#include <odr/internal/util/stream_util.hpp>
#include <odr/internal/util/string_util.hpp>
#include <odr/internal/xml/xml_util.hpp>

#include <algorithm>
#include <mutex>
Expand Down Expand Up @@ -248,7 +249,7 @@ void write_body_begin(const Document &document, const WritingState &state) {
if (const std::optional<std::string> locale = document.locale();
locale.has_value() &&
document.document_type() == DocumentType::spreadsheet) {
clb("data-odr-locale", *locale);
clb("data-odr-locale", xml::escape_attribute(*locale));
}
}
// not an editing fact: a read-only sheet has a pin to clear
Expand Down Expand Up @@ -460,11 +461,12 @@ class HtmlServiceImpl final : public HtmlService {
m_fragments{std::move(fragments)} {
m_views.emplace_back(std::make_shared<HtmlDocumentView>(
*this, "document", 0, "document.html", m_fragments));
for (const auto &fragment : m_fragments) {
if (fragment->name() == "document") {
continue;
// the one fragment of a text document is the document view itself
if (m_document.document_type() != DocumentType::text) {
for (const auto &fragment : m_fragments) {
m_views.emplace_back(
std::make_shared<HtmlFragmentView>(*this, fragment));
}
m_views.emplace_back(std::make_shared<HtmlFragmentView>(*this, fragment));
}
}

Expand Down
32 changes: 30 additions & 2 deletions test/src/html_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ TEST(html, an_editable_cut_sheet_states_its_whole_extent) {
}

TEST(html, an_editable_sheet_states_its_locale) {
const DecodedFile file = open(File::from_memory(
const std::string source =
R"(<?xml version="1.0" encoding="UTF-8"?>)"
R"(<office:document)"
R"( xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0")"
Expand All @@ -1018,13 +1018,25 @@ TEST(html, an_editable_sheet_states_its_locale) {
R"(</style:default-style></office:styles>)"
R"(<office:body><office:spreadsheet><table:table table:name="s">)"
R"(<table:table-row><table:table-cell/></table:table-row>)"
R"(</table:table></office:spreadsheet></office:body></office:document>)"));
R"(</table:table></office:spreadsheet></office:body></office:document>)";

const DecodedFile file = open(File::from_memory(source));
EXPECT_NE(
render_sheet(file, editing_config()).find(R"(data-odr-locale="de-DE")"),
std::string::npos);
EXPECT_EQ(render_sheet(file, HtmlConfig()).find(R"(data-odr-locale=")"),
std::string::npos);
std::string malformed = source;
const std::string language = R"(fo:language="de")";
malformed.replace(malformed.find(language), language.size(),
R"(fo:language="de&amp;&quot; data-injected=&quot;yes")");
const std::string page =
render_sheet(open(File::from_memory(malformed)), editing_config());
EXPECT_NE(
page.find(
R"(data-odr-locale="de&amp;&quot; data-injected=&quot;yes-DE")"),
std::string::npos);
EXPECT_EQ(page.find(R"( data-injected="yes)"), std::string::npos);
}

TEST(html, a_formatted_number_states_its_value) {
Expand Down Expand Up @@ -1717,3 +1729,19 @@ TEST(html, document_lengths_cannot_inject_styles_or_attributes) {
EXPECT_NE(page.find("text"), std::string::npos);
}
}

TEST(html, a_sheet_named_document_keeps_its_own_view) {
const auto file = fods_file(
fods_row(fods_cell("first")), "",
R"(<table:table table:name="document"><table:table-row><table:table-cell>)"
R"(<text:p>second</text:p></table:table-cell></table:table-row></table:table>)");
const HtmlService service = html::translate(file, HtmlConfig());
ASSERT_EQ(service.list_views().size(), 3u);
const HtmlView &view = view_at(service, "sheet1.html");
EXPECT_EQ(view.name(), "document");
EXPECT_TRUE(service.exists(view.path()));
std::ostringstream page;
service.write(view.path(), page);
EXPECT_NE(page.str().find("second</td>"), std::string::npos);
EXPECT_EQ(page.str().find("first</td>"), std::string::npos);
}
Loading