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

Fixed side effect from invocation of cleaner in unfluff.lazy #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

franza
Copy link
Contributor

@franza franza commented Aug 29, 2014

I was sure that I checked that for #16 but it seems that I missed that.

cleaner mutates original doc object so doc needs to be re-calculated. So right now after cleaner is applied we will suffer from side effect. Consider next example:

[fs, unfluff] = ['fs', 'unfluff'].map require

html = fs.readFileSync('test_tags_kexp.html', 'utf8')

doc1 = unfluff.lazy html
doc2 = unfluff.lazy html

console.log 'tags1: ', doc1.tags() # ['Dennis Morton', 'film', 'kusp film review', 'Stand Up Guys']
console.log 'text1: ', doc1.text()

console.log 'text2: ', doc2.text()
console.log 'tags2: ', doc2.tags() # [ ]

Using this code over test_tags_kexp.html fixture we will have different results for tags() since cleaner is called inside text().
So when cleaner is called we need to reload document. Besides, I added some refactoring.

@ageitgey
Copy link
Owner

Thanks for catching this! I'll take a look in detail when I have some time this weekend.

@franza
Copy link
Contributor Author

franza commented Aug 29, 2014

Sure. If you have ideas how we can avoid reloading document bring it up.

@ageitgey
Copy link
Owner

ageitgey commented Sep 8, 2014

Sorry, I've been lax on reviewing this. Still plan to get to this very soon. Thanks!

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.

2 participants