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

.html(number) and .text(number) break things #703

Closed
Rycochet opened this issue Apr 21, 2015 · 2 comments
Closed

.html(number) and .text(number) break things #703

Rycochet opened this issue Apr 21, 2015 · 2 comments

Comments

@Rycochet
Copy link
Contributor

Not sure exactly what's going on - but looks like when they're set they're not being converted into a string, so when you try to change them later it's not behaving properly.

(Pseudo code as this was found in a larger project)

$("span").html(123).html(123) silently fills it with an empty string.

$("span").text(123).text(123) causes an exception -

Warning: Object 312 has no method 'replace' Use --force to continue.
TypeError: Object 312 has no method 'replace'
    at Object.encodeXML (...\node_modules\cheerio\node_modules\entities\lib\encode.js:58:6)
    at renderText (...\node_modules\cheerio\node_modules\dom-serializer\index.js:166:21)
    at module.exports (...\node_modules\cheerio\node_modules\dom-serializer\index.js:121:17)
    at renderTag (...\node_modules\cheerio\node_modules\dom-serializer\index.js:146:14)
    at module.exports (...\node_modules\cheerio\node_modules\dom-serializer\index.js:113:17)
    at renderTag (...\node_modules\cheerio\node_modules\dom-serializer\index.js:146:14)
    at module.exports (...\node_modules\cheerio\node_modules\dom-serializer\index.js:113:17)
    at renderTag (...\node_modules\cheerio\node_modules\dom-serializer\index.js:146:14)
    at module.exports ...\node_modules\cheerio\node_modules\dom-serializer
\index.js:113:17)
    at renderTag (...\node_modules\cheerio\node_modules\dom-serializer\inde
x.js:146:14)

Both $("span").html("" + 123).html("" + 123) and $("span").text("" + 123).text("" + 123) work as expected.

Maybe coerce the type at some point?

@fb55
Copy link
Member

fb55 commented Apr 21, 2015

PRs welcome :)

@fb55
Copy link
Member

fb55 commented Dec 22, 2020

Fixed in #704

@fb55 fb55 closed this as completed Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants