mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-21 14:59:57 +00:00
fix(ui): mentions formatting and AUT failure fix (#22502)
* fix mentions formatting * added unit test
This commit is contained in:
parent
d097f4505f
commit
4a267e276e
@ -40,4 +40,50 @@ describe('getSanitizeContent', () => {
|
|||||||
|
|
||||||
expect(result).toBe(`<p>abc</p>`);
|
expect(result).toBe(`<p>abc</p>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('HTML Encoding Prevention', () => {
|
||||||
|
it('should NOT encode entity links with HTML entities', () => {
|
||||||
|
const input = '<#E::team::Accounting|@Accounting>';
|
||||||
|
const result = getSanitizeContent(input);
|
||||||
|
|
||||||
|
// Should NOT contain HTML encoded entities
|
||||||
|
expect(result).not.toContain('<');
|
||||||
|
expect(result).not.toContain('>');
|
||||||
|
expect(result).not.toContain('&');
|
||||||
|
|
||||||
|
// Should contain the original entity link format
|
||||||
|
expect(result).toBe('<#E::team::Accounting|@Accounting>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT encode multiple entity links with HTML entities', () => {
|
||||||
|
const input =
|
||||||
|
'Hello <#E::team::Accounting|@Accounting> and <#E::user::john.doe|@john.doe>';
|
||||||
|
const result = getSanitizeContent(input);
|
||||||
|
|
||||||
|
// Should NOT contain HTML encoded entities
|
||||||
|
expect(result).not.toContain('<');
|
||||||
|
expect(result).not.toContain('>');
|
||||||
|
expect(result).not.toContain('&');
|
||||||
|
|
||||||
|
// Should contain the original entity link format
|
||||||
|
expect(result).toBe(
|
||||||
|
'Hello <#E::team::Accounting|@Accounting> and <#E::user::john.doe|@john.doe>'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT encode entity links even when mixed with HTML content', () => {
|
||||||
|
const input =
|
||||||
|
'<div>Hello</div><#E::team::Accounting|@Accounting><span>World</span>';
|
||||||
|
const result = getSanitizeContent(input);
|
||||||
|
|
||||||
|
// Should NOT contain HTML encoded entities for the entity link
|
||||||
|
expect(result).not.toContain('<#E::team::Accounting|@Accounting>');
|
||||||
|
expect(result).not.toContain(
|
||||||
|
'&lt;#E::team::Accounting|@Accounting&gt;'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should contain the original entity link format
|
||||||
|
expect(result).toContain('<#E::team::Accounting|@Accounting>');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -13,5 +13,25 @@
|
|||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
export const getSanitizeContent = (html: string): string => {
|
export const getSanitizeContent = (html: string): string => {
|
||||||
return DOMPurify.sanitize(html);
|
// First, temporarily replace entity links to protect them from encoding
|
||||||
|
const entityLinkRegex = /<#E::[^>]+>/g;
|
||||||
|
const entityLinks: string[] = [];
|
||||||
|
let entityLinkIndex = 0;
|
||||||
|
|
||||||
|
const protectedHtml = html.replace(entityLinkRegex, (match) => {
|
||||||
|
entityLinks.push(match);
|
||||||
|
|
||||||
|
return `__ENTITY_LINK_${entityLinkIndex++}__`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sanitize the content with standard DOMPurify settings
|
||||||
|
const sanitizedContent = DOMPurify.sanitize(protectedHtml);
|
||||||
|
|
||||||
|
// Restore entity links
|
||||||
|
let restoredContent = sanitizedContent;
|
||||||
|
entityLinks.forEach((link, index) => {
|
||||||
|
restoredContent = restoredContent.replace(`__ENTITY_LINK_${index}__`, link);
|
||||||
|
});
|
||||||
|
|
||||||
|
return restoredContent;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user