From afc6cd16d3afc9965e40846b88678d975463ea8c Mon Sep 17 00:00:00 2001 From: "jminta%gmail.com" Date: Mon, 24 Jul 2006 18:01:04 +0000 Subject: [PATCH] Bug 341837 microsummary service should impose limit on length of microsummary, r=myk --- .../src/nsMicrosummaryService.js.in | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/browser/components/microsummaries/src/nsMicrosummaryService.js.in b/browser/components/microsummaries/src/nsMicrosummaryService.js.in index 229df343bee3..f0a026524ed0 100644 --- a/browser/components/microsummaries/src/nsMicrosummaryService.js.in +++ b/browser/components/microsummaries/src/nsMicrosummaryService.js.in @@ -73,6 +73,8 @@ const FIELD_CONTENT_TYPE = NC_NS + "ContentType"; const FIELD_BOOKMARK_URL = NC_NS + "URL"; #endif +const MAX_SUMMARY_LENGTH = 4096; + function MicrosummaryService() {} MicrosummaryService.prototype = { @@ -1282,11 +1284,16 @@ MicrosummaryGenerator.prototype = { }, generateMicrosummary: function MSD_generateMicrosummary(pageContent) { - if (this.content) - return this.content.replace(/^\s+|\s+$/g, ""); - else if (this.template) + if (this.content) { + var content = this.content.replace(/^\s+|\s+$/g, ""); + if (content.length > MAX_SUMMARY_LENGTH) + content = content.substring(0, MAX_SUMMARY_LENGTH); + return content; + } else if (this.template) { + // Note that _processTemplate truncates the summary for us, so we don't + // need to do anything more here return this._processTemplate(pageContent); - else + } else throw("generateMicrosummary called on uninitialized microsummary generator"); }, @@ -1328,7 +1335,11 @@ MicrosummaryGenerator.prototype = { // XXX When we support HTML microsummaries we'll need to do something // more sophisticated than just returning the text content of the fragment. - return fragment.textContent; + var content = fragment.textContent; + if (content.length > MAX_SUMMARY_LENGTH) + content = content.substring(0, MAX_SUMMARY_LENGTH); + + return content; } };