Improve web props (#313)

* fix: improve props

* fix: property
main
bokuweb 2021-07-01 16:54:03 +09:00 committed by GitHub
parent 0740dac833
commit 6c9b7a1c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -45,8 +45,10 @@ impl WebExtension {
}
pub fn property(mut self, name: impl Into<String>, value: impl Into<String>) -> Self {
let v = value.into();
let v = format!("&quot;{}&quot;", escape(&v).replace("&quot;", "\\&quot;"));
self.properties
.push(WebExtensionProperty::new(name, escape(&value.into())));
.push(WebExtensionProperty::new(name, &v));
self
}
}
@ -103,7 +105,7 @@ mod tests {
<we:reference id="7f33b723-fb58-4524-8733-dbedc4b7c095" version="1.0.0.0" store="developer" storeType="Registry" />
<we:alternateReferences />
<we:properties>
<we:property name="hello" value="world" />
<we:property name="hello" value="&quot;world&quot;" />
</we:properties>
<we:bindings />
<we:snapshot xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />

View File

@ -1,6 +1,6 @@
{
"name": "docx-wasm",
"version": "0.0.200",
"version": "0.0.201",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>",

View File

@ -17212,7 +17212,7 @@ exports[`writer should write webextension 7`] = `
<we:reference id=\\"7f33b723-fb58-4524-8733-dbedc4b7c095\\" version=\\"1.0.0.0\\" store=\\"developer\\" storeType=\\"Registry\\" />
<we:alternateReferences />
<we:properties>
<we:property name=\\"hello\\" value=\\"&quot;world&quot;\\" />
<we:property name=\\"hello\\" value=\\"&quot;{\\\\&quot;hello\\\\&quot;:\\\\&quot;world\\\\&quot;}&quot;\\" />
</we:properties>
<we:bindings />
<we:snapshot xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" />

View File

@ -306,7 +306,7 @@ describe("writer", () => {
"1.0.0.0",
"developer",
"Registry"
).property("hello", '"world"')
).property("hello", JSON.stringify({ hello: "world" }))
)
.build();
writeFileSync("../output/webextension.docx", buffer);