Skip to content
Snippets Groups Projects
Commit 0ecd0f57 authored by Igor Markin's avatar Igor Markin
Browse files

Merge branch 'fix-validation-cases' into 'master'

Fix validation cases

See merge request light/clients/utils!36
parents 1cc12fe3 33fe37c0
No related branches found
No related tags found
1 merge request!36Fix validation cases
......@@ -103,4 +103,28 @@ describe("MimeVerificationService", () => {
expect(normalizedHtml).toContain(outHTML);
});
it("fixes issue 33", () => {
const sentHTML = fs
.readFileSync(path.resolve(__dirname, "data/outlook_issue_33_sent.html"))
.toString();
const receivedHTML = fs
.readFileSync(
path.resolve(__dirname, "data/outlook_issue_33_received.html")
)
.toString();
const normalizedSentHTML = MimeVerificationService.normalizeVendorHtml(
sentHTML,
"OUTLOOK"
);
const normalizedReceivedHTML = MimeVerificationService.normalizeVendorHtml(
receivedHTML,
"OUTLOOK"
);
expect(normalizedReceivedHTML).toContain(normalizedSentHTML);
});
});
<span>
<!-- https://code.vereign.com/light/clients/outlookaddin/-/issues/33 -->
<div>
<ol>
<li>
<a href="https://vk.com/alexey.lunin0" class="x_left_row"><span class="x_left_label x_inl_bl"><br class="x_Apple-interchange-newline">Моя страница</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/feed" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Новости</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/im" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Мессенджер</span><span class="x_left_count_wrap x_fl_r"><span class="x_inl_bl x_left_count">1</span></span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/friends" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Друзья</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/groups" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Сообщества</span><span class="x_left_count_wrap x_fl_r"><span class="x_inl_bl x_left_count">10</span></span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/albums16820605" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Фотографии</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/audios16820605" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Музыка</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/video" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Видео</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/clips" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Клипы</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/apps" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Игры</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<div class="x_more_div x_l_main"></div>
<li class="x_AppLeftMenuWithNotify">
<a href="https://vk.com/services" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Мини-приложения</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/vkpay" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">VK Pay</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/worki" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Работа</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<div class="x_more_div"></div>
<li>
<a href="https://vk.com/market" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Маркет</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/bookmarks?from_menu=1" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Закладки</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/docs" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Файлы</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/apps?act=manage" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Управление</span></a>
<div class="x_left_settings">
<div class="x_left_settings_inner"></div>
</div>
</li>
<div class="x_more_div"></div>
<li><a href="https://vk.com/covid19#utm_source=vk&amp;utm_medium=cpc&amp;utm_campaign=web_left_nav" class="x_left_row"><span class="x_left_icon x_fl_l"></span><span class="x_left_label x_inl_bl">Коронавирус</span></a></li>
</ol>
<br>
</div>
<div>
<br>
<div id="x_test-for-us"><a href="https://office.test.vereign.com/?q=CiDMDkdwWXSSqKTkZmupXsPRSREzYa9zE8KNfqdzEIHO2BIgzcz5rWorySQ4mm65FRbg6Bbtt75PNt2iqmIi3BcbsWs=&amp;timestamp=1605680510307" target="_blank"><img class="x_qrcode.png" name="x_qrcode.png" id="x_qrcode.png" alt="qrcode.png" width="160" src="cid:f6fe7676-87f4-4d86-8963-f36d3970331d"> </a></div>
<br>
</div>
</span>
<div>
<!-- https://code.vereign.com/light/clients/outlookaddin/-/issues/33 -->
<ol>
<li>
<a href="https://vk.com/alexey.lunin0" class="left_row"><span class="left_label inl_bl"><br class="Apple-interchange-newline">Моя страница</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/feed" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Новости</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/im" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Мессенджер</span><span class="left_count_wrap fl_r"><span class="inl_bl left_count">1</span></span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/friends" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Друзья</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/groups" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Сообщества</span><span class="left_count_wrap fl_r"><span class="inl_bl left_count">10</span></span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/albums16820605" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Фотографии</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/audios16820605" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Музыка</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/video" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Видео</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/clips" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Клипы</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/apps" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Игры</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<div class="more_div l_main"></div>
<li class="AppLeftMenuWithNotify">
<a href="https://vk.com/services" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Мини-приложения</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/vkpay" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">VK Pay</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/worki" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Работа</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<div class="more_div"></div>
<li>
<a href="https://vk.com/market" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Маркет</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/bookmarks?from_menu=1" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Закладки</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/docs" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Файлы</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<li>
<a href="https://vk.com/apps?act=manage" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Управление</span></a>
<div class="left_settings">
<div class="left_settings_inner"></div>
</div>
</li>
<div class="more_div"></div>
<li><a href="https://vk.com/covid19#utm_source=vk&amp;utm_medium=cpc&amp;utm_campaign=web_left_nav" class="left_row"><span class="left_icon fl_l"></span><span class="left_label inl_bl">Коронавирус</span></a></li>
</ol>
<br>
</div>
......@@ -185,7 +185,7 @@ const normalizeVendorHtml = (htmlString: string, vendor: string): string => {
document = window.document;
}
const mimeBody = document.firstChild.lastChild;
const mimeBody = document.body;
const amendNodesFunction = vendorAmendingFunctions[vendor];
if (amendNodesFunction) {
......
......@@ -59,53 +59,70 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
/**
* Get rid of attachments panes
*/
const attachmentsPanes = document.querySelectorAll(
"#OwaReferenceAttachments"
const attachmentsPanesConatiner = document.getElementById(
"OwaReferenceAttachments"
);
const attachmentsPanesEnds = document.querySelectorAll(
"#OwaReferenceAttachmentsEnd"
const attachmentsPanesContainerEnd = document.getElementById(
"OwaReferenceAttachmentsEnd"
);
attachmentsPanesEnds.forEach((pane) => pane.parentNode.removeChild(pane));
attachmentsPanes.forEach((pane) => {
const as = pane.querySelectorAll("a");
as.forEach((a) => {
cloneAnchorFromPane(a, pane as HTMLElement);
if (attachmentsPanesConatiner) {
const as = attachmentsPanesConatiner.getElementsByTagName("a");
Array.from(as).forEach((a) => {
cloneAnchorFromPane(a, attachmentsPanesConatiner as HTMLElement);
});
});
attachmentsPanes.forEach((pane) => {
pane.parentNode.removeChild(pane);
});
attachmentsPanesConatiner.parentNode.removeChild(attachmentsPanesConatiner);
}
attachmentsPanesContainerEnd &&
attachmentsPanesContainerEnd.parentNode.removeChild(
attachmentsPanesContainerEnd
);
/**
* Unwind spans, because sometimes Outlook wraps everything into span after sending
*/
const spans = document.querySelectorAll("span");
const spans = document.getElementsByTagName("span");
spans.forEach((span) => {
let child = span.firstChild;
while (child) {
if (child.nodeName.toLowerCase() === "span") {
child = child.nextSibling;
continue;
}
let parent = span.parentNode;
let lastSpan = span as Node;
while (parent && parent.nodeName.toLowerCase() === "span") {
lastSpan = parent;
parent = parent.parentNode;
}
parent.insertBefore(child.cloneNode(true), lastSpan);
/**
* Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
*/
const spansDepths: { depth?: Array<Node> } = {};
Array.from(spans).forEach((span: Node) => {
let descendant = span;
let parent = descendant.parentNode;
let depth = 0;
while (parent && descendant !== parent) {
descendant = parent;
parent = descendant.parentNode;
depth++;
}
child = child.nextSibling;
if (!spansDepths[depth]) {
spansDepths[depth] = [];
}
spansDepths[depth].push(span);
});
spans.forEach((span) => span.parentNode.removeChild(span));
Object.keys(spansDepths)
.sort((a, b) => parseInt(b) - parseInt(a))
.forEach((depth) => {
spansDepths[depth].forEach((span) => {
let child = span.firstChild;
const parent = span.parentNode;
while (child) {
parent.insertBefore(child.cloneNode(true), span);
child = child.nextSibling;
}
span.parentNode.removeChild(span);
});
});
};
export const amendGmailNodes = (document: HTMLDocument): void => {
......@@ -113,7 +130,9 @@ export const amendGmailNodes = (document: HTMLDocument): void => {
* Look for attachments panes and remove everything but liks
*/
const attachmentsPanes = document.querySelectorAll(".gmail_chip");
const attachmentsPanes = Array.from(
document.getElementsByClassName("gmail_chip")
);
attachmentsPanes.forEach((pane) => {
const as = pane.querySelectorAll("a");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment