fix: bound retained rich text content
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
type OneNoteContentBlock,
|
||||
type OneNoteTextBlock,
|
||||
} from '../src/onenote/index.js';
|
||||
import type { ParserDiagnostic } from '../src/onenote/model/diagnostics.js';
|
||||
import { parseContentObjects } from '../src/onenote/one/content.js';
|
||||
import { JCID, PROPERTY } from '../src/onenote/one/constants.js';
|
||||
import type {
|
||||
@@ -207,6 +208,47 @@ describe('OneNote rich-content model', () => {
|
||||
.reduce((total, stroke) => total + stroke.points.length, 0);
|
||||
expect(parsedPoints).toBeLessThanOrEqual(100);
|
||||
});
|
||||
|
||||
it('bounds retained rich text across content blocks', () => {
|
||||
const guid = '{33333333-3333-3333-3333-333333333333}';
|
||||
const firstId = id(guid, 1);
|
||||
const secondId = id(guid, 2);
|
||||
const richTextObject = (objectId: ExGuid, text: string) =>
|
||||
object(
|
||||
objectId,
|
||||
JCID.RichTextNode,
|
||||
props(
|
||||
bytesEntry(PROPERTY.RichEditTextUnicode, Buffer.from(text, 'utf16le'))
|
||||
),
|
||||
guid
|
||||
);
|
||||
const objects = [
|
||||
richTextObject(firstId, 'first'),
|
||||
richTextObject(secondId, 'second'),
|
||||
];
|
||||
const diagnostics: ParserDiagnostic[] = [];
|
||||
const blocks = parseContentObjects([firstId, secondId], {
|
||||
space: {
|
||||
id: id(guid, 0),
|
||||
roots: new Map(),
|
||||
objects: new Map(
|
||||
objects.map((value) => [exGuidKey(value.id), value] as const)
|
||||
),
|
||||
},
|
||||
limits: { ...DEFAULT_ONENOTE_PARSER_LIMITS, maxExtractedTextChars: 8 },
|
||||
diagnostics,
|
||||
resources: new Map(),
|
||||
});
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0]).toMatchObject({ kind: 'text', text: 'first' });
|
||||
expect(diagnostics).toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: 'CONTENT_PARSE_FAILED',
|
||||
message: expect.stringContaining('Rich-text character count exceeds 8'),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function parseSyntheticLink(href: string): OneNoteTextBlock {
|
||||
|
||||
Reference in New Issue
Block a user