cgiffard / Downsize

Tag safe text truncation for HTML and XML!
BSD 3-Clause "New" or "Revised" License
41 stars 13 forks source link

handle truncating to zero words #5

Closed qzg closed 10 years ago

qzg commented 10 years ago

Issue Summary

The code incorrectly handles numeric zero when truncating. String quoted zero ("0") works.

Steps to Reproduce

$ node
> downsize = require('./index.js')
[Function]
> downsize("<p>this is a <strong>test of word downsizing</strong></p>", {words: 1})
'<p>this</p>'
> downsize("<p>this is a <strong>test of word downsizing</strong></p>", {words: 0})
'<p>this is a <strong>test of word downsizing</strong></p>'
> downsize("<p>this is a <strong>test of word downsizing</strong></p>", {words: "0"})
'<p></p>'

Technical Details

Downsize Version: master (latest commit: ed2d74dcb7031c3a57b43b73197e40809fa3912e) Client OS: Mac OS X Node Version: 0.10.12

adam-zethraeus commented 10 years ago

can this be merged as long as we add a setting for ghost initial keeping?

cgiffard commented 10 years ago

Maybe it's just me being picky, but I want to adjust the logic a bit. I'm pretty happy with it overall. :)

cgiffard commented 10 years ago

(Also I'll need to do an offline merge.)

adam-zethraeus commented 10 years ago

fixed.