fix: bound retained rich text content
This commit is contained in:
@@ -54,6 +54,7 @@ import {
|
||||
export interface OneNoteContentBudget {
|
||||
blocks: number;
|
||||
textRuns: number;
|
||||
textCharacters: number;
|
||||
tableCells: number;
|
||||
inkPoints: number;
|
||||
}
|
||||
@@ -72,7 +73,13 @@ interface ContentContext extends OneNoteContentParseOptions {
|
||||
}
|
||||
|
||||
export function createContentBudget(): OneNoteContentBudget {
|
||||
return { blocks: 0, textRuns: 0, tableCells: 0, inkPoints: 0 };
|
||||
return {
|
||||
blocks: 0,
|
||||
textRuns: 0,
|
||||
textCharacters: 0,
|
||||
tableCells: 0,
|
||||
inkPoints: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/** Parse page graph roots into an inert, recursively structured content tree. */
|
||||
@@ -235,6 +242,7 @@ function parseRichText(
|
||||
let sourceText = optionalString(object, PROPERTY.RichEditTextUnicode);
|
||||
sourceText ??= optionalLatin1(object, PROPERTY.TextExtendedAscii);
|
||||
sourceText = (sourceText ?? '').split('\0').join('');
|
||||
incrementTextCharacterBudget(context, sourceText.length);
|
||||
|
||||
const paragraphStyleId = objectReferences(object, PROPERTY.ParagraphStyle)[0];
|
||||
const paragraphStyle = paragraphStyleId
|
||||
@@ -1223,6 +1231,22 @@ function incrementTextRunBudget(context: ContentContext, amount: number): void {
|
||||
}
|
||||
}
|
||||
|
||||
function incrementTextCharacterBudget(
|
||||
context: ContentContext,
|
||||
amount: number
|
||||
): void {
|
||||
const next = context.budget.textCharacters + amount;
|
||||
if (
|
||||
!Number.isSafeInteger(next) ||
|
||||
next > context.limits.maxExtractedTextChars
|
||||
) {
|
||||
throw new Error(
|
||||
`Rich-text character count exceeds ${context.limits.maxExtractedTextChars}`
|
||||
);
|
||||
}
|
||||
context.budget.textCharacters = next;
|
||||
}
|
||||
|
||||
function incrementTableCellBudget(context: ContentContext): void {
|
||||
context.budget.tableCells += 1;
|
||||
if (context.budget.tableCells > context.limits.maxTableCells) {
|
||||
|
||||
Reference in New Issue
Block a user