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

text() not working as expected in 1.0.0-rc2 #1112

Closed
plumpNation opened this issue Nov 22, 2017 · 3 comments
Closed

text() not working as expected in 1.0.0-rc2 #1112

plumpNation opened this issue Nov 22, 2017 · 3 comments

Comments

@plumpNation
Copy link

plumpNation commented Nov 22, 2017

1.0.0-rc2

const svgString = '<?xml version="1.0" encoding="utf-8"?><svg><style>path{fill:red}</style></svg>';

const $ = cheerio.load(svgString, {xmlMode: true);

$('styles').each((index, element) => {
    console.log($(element).text()); // outputs: ''
    console.log($(element).html()); // outputs: 'path{fill:red}'
});

I have rolled back to 0.22.0 and it works fine.

@plumpNation plumpNation changed the title text() not working as expected text() not working as expected in 1.0.0-rc2 Nov 22, 2017
@nover
Copy link

nover commented Nov 24, 2017

Having a similar issue here with the following test case in our project:

mocha v4 test suite with unexpected required as expect

it('returns text of title tag', () => {
    const html = '<html><head><title><b>bold</b> title</title>' +
      '</head><body><h1>Hello</h1></body></html>';

    const $ = cheerio.load(html);
    const theTitle = $('title').text();
    expect('bold title', 'to be', theTitle);
  });

failing with the assertion error:

UnexpectedError:
expected 'bold title' to be '<b>bold</b> title' 

So the <b> tags are not properly stripped.

Working in 0.22.0 and broken in 1.0.0-rc.2

@fb55 fb55 mentioned this issue Feb 21, 2018
4 tasks
@fb55
Copy link
Member

fb55 commented Mar 11, 2018

Duplicate of #1050

@nover's case is expected — <title> tags are special that way.

@fb55 fb55 closed this as completed Mar 11, 2018
@nover
Copy link

nover commented Mar 12, 2018

@fb55 Ok I see, so basically the old version of cheerio is parsing it incorrectly. Any suggestions on how to migrate to 1.0 and get the title element out without any extra tags? :)

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

3 participants