Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent an infinite loop when the trimmed text is shorter than the condensed length #6

Merged
merged 1 commit into from
Jan 8, 2013

Conversation

eventualbuddha
Copy link

When the contents of the element are only text (clone.html().length == clone.text().length) and the substring is as long as or longer than the condensed length (loc >= opts.condensedLength) and the trimmed body is shorter than the condensed length (clone.text().length < opts.condensedLength), then delta will be zero and the do/while loop will be stuck in an infinite loop. Here's an example where this reliably happens:

<div id="demo">
              I wandered around the streets interviewing people and filming the sights on the day of the Royal wedding, I've never seen so many Union Jacks.

              Shot at 50fps using a Canon 7D, and because I didn't have my sound device I also used it to record the audio, holding it on the end of the tripod like a microphone.

              Music Soda by Cinematic Orchestra 

              twitter.com/davedingo
</div>

Then run this code:

$('#demo').condense({condensedLength: 400});

…ndensed length.


When the contents of the element are only text (html.length == text.length) and the substring is as long as or longer than the condensed length (loc >= opts.condensedLength) and the trimmed body is shorter than the condensed length (clone.text().length < opts.condensedLength), then delta will be zero and the do/while loop will be stuck in an infinite loop.
@mfollett
Copy link
Contributor

mfollett commented Sep 1, 2011

good fix!

jsillitoe added a commit that referenced this pull request Jan 8, 2013
Prevent an infinite loop when the trimmed text is shorter than the condensed length
@jsillitoe jsillitoe merged commit ead00a7 into jsillitoe:master Jan 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants