Skip to content

Commit

Permalink
Merge pull request #918 from vandenoever/settings
Browse files Browse the repository at this point in the history
If there is no <office:settings/> element, save an empty <office:document-settings/> element.
  • Loading branch information
vandenoever committed Sep 11, 2015
2 parents 97ebc92 + 47fa509 commit 999917d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 5 additions & 8 deletions webodf/lib/odf/OdfContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,18 +993,15 @@
* @return {!string}
*/
function serializeSettingsXml() {
var serializer,
var serializer = new xmldom.LSSerializer(),
/**@type{!string}*/
s = "";
s = createDocumentElement("document-settings");
// <office:settings/> is optional, but if present must have at least one child element
if (self.rootElement.settings && self.rootElement.settings.firstElementChild) {
serializer = new xmldom.LSSerializer();
s = createDocumentElement("document-settings");
serializer.filter = new odf.OdfNodeFilter();
s += serializer.writeToString(self.rootElement.settings, odf.Namespaces.namespaceMap);
s += "</office:document-settings>";
}
return s;
return s + "</office:document-settings>";
}
/**
* @return {!string}
Expand Down Expand Up @@ -1306,8 +1303,8 @@
date = new Date(),
settings;

settings = serializeSettingsXml();
if (settings) {
if (partMimetypes["settings.xml"]) {
settings = serializeSettingsXml();
// Optional according to package spec
// See http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__440346_826425813
data = runtime.byteArrayFromString(settings, "utf8");
Expand Down
4 changes: 1 addition & 3 deletions webodf/tests/odf/OdfContainerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ odf.OdfContainerTests = function OdfContainerTests(runner) {
t.odf = new odf.OdfContainer(path, function (odf) {
t.odf = odf;
r.shouldBe(t, "t.odf.state", "odf.OdfContainer.DONE");
// The value would only become null if it was a node. By default, random unspecified
// attributes on anything are undefined.
r.shouldBe(t, "t.odf.rootElement.settings", "undefined");
r.shouldBe(t, "t.odf.rootElement.settings", "null");
checkMimeType(t, path, callback);
});
});
Expand Down

0 comments on commit 999917d

Please sign in to comment.