huang47 / nodejs-html-truncate

truncate html text and keep tag safe
77 stars 30 forks source link

bug with elipsis #9

Closed GriffinHeart closed 9 years ago

GriffinHeart commented 10 years ago
    input = 'feafawefaefawfafeafafeafeeaefa feawfaweffeawfeafeafaefafeafafaeafeafeafaefafeafaefaefa <span class="wurl"><a href="http://google.com" target="_blank" rel="nofollow">http://google.com</a></span>';
    actual = truncate(input, 100);
    expect = 'feafawefaefawfafeafafeafeeaefa feawfaweffeawfeafeafaefafeafafaeafeafeafaefafeafaefaefa <span class="wurl"><a href="http://google.com" target="_blank" rel="nofollow">http://google...</a></span>';
    assert.strictEqual(actual, expect);

is this a bug?

here is a more simple version:

    input  = 'thisare19characters <a href="http://google.com">http://google.com</a>';
    actual = truncate(input, 33);
    expect = 'thisare19characters <a href="http://google.com">http://google...</a>';
    assert.strictEqual(actual, expect);

I think the problem comes from here https://github.com/huang47/nodejs-html-truncate/blob/master/truncate.js#L166 :

After breaking from the loop string is the remaining content of the string which doesn't make sense to compare for maxLength. shouldn't this be: total > maxLength?

tildedave commented 9 years ago

I am seeing this as well

tildedave commented 9 years ago

Opened #10 to resolve