1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Desktop: Fixes #12295: Fix import of certain OneNote files that contain invalid properties (#12338)

This commit is contained in:
pedr
2025-06-06 06:04:50 -03:00
committed by GitHub
parent 608dbab453
commit c75b48fbb1
6 changed files with 120 additions and 14 deletions

View File

@@ -245,4 +245,18 @@ describe('InteropService_Importer_OneNote', () => {
} }
BaseModel.setIdGenerator(originalIdGenerator); BaseModel.setIdGenerator(originalIdGenerator);
}); });
skipIfNotCI('should use default value for EntityGuid and InkBias if not found', async () => {
let idx = 0;
const originalIdGenerator = BaseModel.setIdGenerator(() => String(idx++));
const notes = await importNote(`${supportDir}/onenote/ink_bias_and_entity_guid.zip`);
// InkBias bug
expect(notes.find(n => n.title === 'Marketing Funnel & Training').body).toMatchSnapshot();
// EntityGuid
expect(notes.find(n => n.title === 'Decrease support costs').body).toMatchSnapshot();
BaseModel.setIdGenerator(originalIdGenerator);
});
}); });

View File

@@ -1446,3 +1446,95 @@ exports[`InteropService_Importer_OneNote should render links properly by ignorin
</body> </body>
</html>" </html>"
`; `;
exports[`InteropService_Importer_OneNote should use default value for EntityGuid and InkBias if not found 1`] = `
"<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta charset="UTF-8" />
<title>Marketing Funnel &amp; Training</title>
<style>
* { margin: 0; padding: 0; font-weight: normal; }
table, tr, td { border-color: #A3A3A3; }
ul, ol { padding: 0; }
.title .outline-element { display: inline; }
.title .outline-element:nth-child(2) { margin-left: 10px !important; }
.container-outline { font-family: Calibri, sans-serif; font-size: 6pt; }
.ink-text, .ink-space { display: inline-block; position: relative; vertical-align: bottom; }
.ink-text { top: 0; left: 0; }
.note-tag-icon { position: relative; }
.note-tag-icon &gt; svg { position: absolute; }
.icon-secondary &gt; svg { position: absolute; fill: black; filter: drop-shadow(0 0 2px white); height: 12px; top: -1px; }
.icon-secondary &gt; .content { position: absolute; color: black; filter: drop-shadow(0 0 2px white); font-size: 10px; color: black; top: -1px; user-select: none; }
</style>
</head>
<body>
<div class="title" style="left: 48px; position: absolute; top: 24px;"><div class="container-outline"><div class="outline-element" style="margin-left: 0px;"><span style="font-family: Trebuchet MS; font-size: 20pt; line-height: 32px;">Marketing Funnel &amp; Training</span></div>
</div><div class="container-outline"><div class="outline-element" style="margin-left: 0px;"><span style="color: rgb(128,128,128); font-family: Calibri; font-size: 10pt; line-height: 16px;">Tuesday, October 06, 2015</span></div>
<div class="outline-element" style="margin-left: 0px;"><span style="color: rgb(128,128,128); font-family: Calibri; font-size: 10pt; line-height: 16px;">12:27 PM</span></div>
</div></div><div class="container-outline" style="left: 48px; position: absolute; top: 115px; width: 624px;"><div class="outline-element" style="margin-left: 0px;"><img src=":/139" /></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Trebuchet MS; font-size: 12pt; line-height: 19px;"> </p></div>
<div class="outline-element" style="margin-left: 0px;"><cite style="color: rgb(89,89,89); font-family: Calibri; font-size: 9pt; line-height: 14px;">From &lt;<a href="http://adamhcohen.com/wp-content/uploads/New-Marketing-Funnel1.JPG" style="">http://adamhcohen.com/wp-content/uploads/New-Marketing-Funnel1.JPG</a>&gt; </cite></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Trebuchet MS; font-size: 12pt; line-height: 19px;"> </p></div>
</div><div class="container-outline" style="left: 72px; position: absolute; top: 475px; width: 146px;"><div class="outline-element" style="margin-left: 0px;"><p style="color: rgb(91,155,213); font-family: Trebuchet MS; font-size: 12pt; line-height: 19px;">Customer Success Management</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="color: rgb(91,155,213); font-family: Trebuchet MS; font-size: 12pt; line-height: 19px;">and</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="color: rgb(91,155,213); font-family: Trebuchet MS; font-size: 12pt; line-height: 19px;">Training</p></div>
</div><img style="height: 170px; left: 57px; overflow: visible; position: absolute; top: 435px; width: 310px;" src=":/140" />
<script>
if (window.parent !== null) {
window.parent.postMessage(window.location.href, '*');
}
</script>
</body></html>"
`;
exports[`InteropService_Importer_OneNote should use default value for EntityGuid and InkBias if not found 2`] = `
"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Decrease support costs</title>
<style>
* { margin: 0; padding: 0; font-weight: normal; }
table, tr, td { border-color: #A3A3A3; }
ul, ol { padding: 0; }
.title .outline-element { display: inline; }
.title .outline-element:nth-child(2) { margin-left: 10px !important; }
.container-outline { font-family: Calibri, sans-serif; font-size: 6pt; }
.ink-text, .ink-space { display: inline-block; position: relative; vertical-align: bottom; }
.ink-text { top: 0; left: 0; }
.note-tag-icon { position: relative; }
.note-tag-icon > svg { position: absolute; }
.icon-secondary > svg { position: absolute; fill: black; filter: drop-shadow(0 0 2px white); height: 12px; top: -1px; }
.icon-secondary > .content { position: absolute; color: black; filter: drop-shadow(0 0 2px white); font-size: 10px; color: black; top: -1px; user-select: none; }
</style>
</head>
<body>
<div class="title" style="left: 48px; position: absolute; top: 24px;"><div class="container-outline"><div class="outline-element" style="margin-left: 0px;"><span style="font-family: Calibri Light; font-size: 20pt; line-height: 32px;">Decrease support costs</span></div>
</div><div class="container-outline"><div class="outline-element" style="margin-left: 0px;"><span style="color: rgb(128,128,128); font-family: Calibri; font-size: 10pt; line-height: 16px;">Saturday, October 10, 2015</span></div>
<div class="outline-element" style="margin-left: 0px;"><span style="color: rgb(128,128,128); font-family: Calibri; font-size: 10pt; line-height: 16px;">11:15 PM</span></div>
</div></div><div class="container-outline" style="left: 48px; position: absolute; top: 88px; width: 624px;"><div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">One of the strategic goals of training <span style="font-style: italic; font-weight: bold;">must</span> be to decrease the cost of customer support. To do this training must teach customers to "<span style="font-weight: bold;">do</span>" not to "know." How many customers call asking to know something?</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
<div class="outline-element" style="margin-left: 0px;"><p style="font-family: Calibri; font-size: 11pt; line-height: 17px;">&nbsp;</p></div>
</div>
<script>
if (window.parent !== null) {
window.parent.postMessage(window.location.href, '*');
}
</script>
</body>
</html>"
`;

View File

@@ -69,9 +69,7 @@ impl<'a> Renderer<'a> {
} }
let path = PathBuf::from(filename); let path = PathBuf::from(filename);
let ext = path let ext = path.extension().unwrap_or_default();
.extension()
.unwrap_or_default();
let base = path let base = path
.as_os_str() .as_os_str()
.to_str() .to_str()

View File

@@ -40,17 +40,15 @@ pub(crate) fn parse(object: &Object) -> Result<Data> {
.unwrap(); .unwrap();
let bias = simple::parse_u8(PropertyType::InkBias, object)? let bias = simple::parse_u8(PropertyType::InkBias, object)?
.map(|bias| match bias { .map(|bias| match bias {
0 => Ok(InkBias::Handwriting), 0 => InkBias::Handwriting,
1 => Ok(InkBias::Drawing), 1 => InkBias::Drawing,
2 => Ok(InkBias::Both), 2 => InkBias::Both,
i => Err(ErrorKind::MalformedOneNoteFileData( _i => InkBias::Both,
format!("invalid ink bias value: {}", i).into(),
)),
}) })
.transpose()? .unwrap_or_else(|| {
.ok_or_else(|| { log_warn!("No InkBias was set. Using default value 'Both'");
ErrorKind::MalformedOneNoteFileData("ink stroke node has no ink bias".into()) return InkBias::Both;
})?; });
let language_code = simple::parse_u32(PropertyType::LanguageId, object)?; let language_code = simple::parse_u32(PropertyType::LanguageId, object)?;
let properties = ObjectReference::parse(PropertyType::InkStrokeProperties, object)? let properties = ObjectReference::parse(PropertyType::InkStrokeProperties, object)?
.ok_or_else(|| { .ok_or_else(|| {

View File

@@ -1,3 +1,4 @@
use crate::log_warn;
use crate::parser::errors::{ErrorKind, Result}; use crate::parser::errors::{ErrorKind, Result};
use crate::parser::fsshttpb::data::cell_id::CellId; use crate::parser::fsshttpb::data::cell_id::CellId;
use crate::parser::fsshttpb::data::exguid::ExGuid; use crate::parser::fsshttpb::data::exguid::ExGuid;
@@ -32,7 +33,10 @@ pub(crate) fn parse(object: &Object) -> Result<Data> {
} }
let entity_guid = simple::parse_guid(PropertyType::NotebookManagementEntityGuid, object)? let entity_guid = simple::parse_guid(PropertyType::NotebookManagementEntityGuid, object)?
.ok_or_else(|| ErrorKind::MalformedOneNoteFileData("page series has no guid".into()))?; .unwrap_or_else(|| {
log_warn!("page series has no guid");
return Guid::nil();
});
let page_spaces = let page_spaces =
ObjectSpaceReference::parse_vec(PropertyType::ChildGraphSpaceElementNodes, object)? ObjectSpaceReference::parse_vec(PropertyType::ChildGraphSpaceElementNodes, object)?
.unwrap_or_default(); .unwrap_or_default();