Skip to content

Commit

Permalink
protecting against infinite loops in truncation code (bug 636884)
Browse files Browse the repository at this point in the history
  • Loading branch information
potch committed Mar 4, 2011
1 parent 2af2e35 commit fa1a82d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions media/js/zamboni/truncation.js
Expand Up @@ -2,26 +2,27 @@ $.fn.vtruncate = function(opts) {
opts = opts || {};
var showTitle = opts.showTitle || false,
truncText = opts.truncText || "…",
split = [" ",""];
split = [" ",""], counter;
this.each(function() {
var $el = $(this),
oldtext = $el.attr("oldtext") || $el.text(),
txt, cutoff;
if ($el.attr("oldtext")) {
oldtext = unescape(oldtext);
$el.text(oldtext);
}
$el.attr("oldtext", oldtext);
$el.attr("oldtext", escape(oldtext));
for (var i in split) {
delim = split[i];
txt = oldtext.split(delim);
cutoff = txt.length;
var done = (this.scrollHeight - this.offsetHeight) < 2,
chunk = Math.ceil(txt.length/2), oc=0, wid, delim;
while (!done) {
for (counter = 0; counter < 10; counter++) {
$el.html(txt.slice(0,cutoff).join(delim)+truncText);
wid = (this.scrollHeight - this.offsetHeight);
if (wid < 2 && chunk == oc) {
done = true;
if ((wid < 2 && chunk == oc) || cutoff < 1) {
break;
} else if (wid > 1) {
cutoff -= chunk;
} else {
Expand Down

0 comments on commit fa1a82d

Please sign in to comment.