MCPcopy Create free account
hub / github.com/github/gh-aw / applyTruncation

Function applyTruncation

actions/setup/js/sanitize_content_core.cjs:1002–1023  ·  view source on GitHub ↗

* Apply truncation limits to content * @param {string} content - The content to truncate * @param {number} [maxLength] - Maximum length of content (default: 524288) * @returns {string} The truncated content

(content, maxLength)

Source from the content-addressed store, hash-verified

1000 * @returns {string} The truncated content
1001 */
1002function applyTruncation(content, maxLength) {
1003 maxLength = maxLength || 524288;
1004 const lines = content.split("\n");
1005 const maxLines = 65000;
1006
1007 // If content has too many lines, truncate by lines (primary limit)
1008 if (lines.length > maxLines) {
1009 const truncationMsg = "\n[Content truncated due to line count]";
1010 const truncatedLines = lines.slice(0, maxLines).join("\n") + truncationMsg;
1011
1012 // If still too long after line truncation, shorten but keep the line count message
1013 if (truncatedLines.length > maxLength) {
1014 return truncatedLines.substring(0, maxLength - truncationMsg.length) + truncationMsg;
1015 } else {
1016 return truncatedLines;
1017 }
1018 } else if (content.length > maxLength) {
1019 return content.substring(0, maxLength) + "\n[Content truncated due to length]";
1020 }
1021
1022 return content;
1023}
1024
1025/**
1026 * Decodes HTML entities to prevent bypass of @mention detection and to ensure

Callers 2

sanitizeContentFunction · 0.85
sanitizeContentCoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected