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 encoding mishaps. Adjusted tests. #499

Merged
merged 1 commit into from
Jun 4, 2014
Merged

Conversation

alexindigo
Copy link
Contributor

Fixed encoding problems I bumped into and saw over different issues here.

/cc #319 #460 #466 #496

@alexindigo alexindigo changed the title #496 Fixed encoding mishaps. Adjusted tests. Fixed encoding mishaps. Adjusted tests. Jun 1, 2014
@@ -28,6 +28,8 @@ var load = exports.load = function(content, options) {

// Add in the root
initialize._root = root;
// store options
initialize._options = options;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to pass options object to .html method.

@fb55
Copy link
Member

fb55 commented Jun 2, 2014

Nice patch in general. Would you mind submitting the renderer patches to dom-serializer? Otherwise, #458 isn't mergeable.

@alexindigo
Copy link
Contributor Author

Done – cheeriojs/dom-serializer#4

Although I'm not sure if makes total sense, since half of the job was already done.
Added more tests though.

@fb55
Copy link
Member

fb55 commented Jun 3, 2014

@alexindigo Could you update this to fix the failing test case?

@alexindigo
Copy link
Contributor Author

Updated PR.

@alexindigo
Copy link
Contributor Author

PS. Btw, somewhat unrelated I noticed that in package.json it depends on [email protected], and at the moment CSSselect is at 0.7.0 version, is it intentionally left at older version?

dom = $.load(str, {xmlMode: true});

expect(dom('MixedCaseTag').get(0).name).to.equal('MixedCaseTag');
expect(dom.html()).to.be(str);
expect(dom.html()).to.be(expected);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope of this PR, but Cheerio#html won't pass any options, leading to unexpected behavior for $("MixedCaseTag").html().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow you on this one, does it mean you don't want .html() to respect xmlMode:true flag?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In contrary: Currently, Cheerio#html doesn't pass any options to $.html, meaning xmlMode will simply be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does inherit options set on load:

(from lib/static.js)

var load = exports.load = function(content, options) {
// ...
  // store options
  initialize._options = options;
//...
}
var html = exports.html = function(dom) {
// ...
  // sometimes $.html() used without preloading html
  // so fallback non existing options to the default ones
  var options = _.defaults(this._options || {}, Cheerio.prototype.options);
// ...
}

It was part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this test proves it. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm referring to lib/api/manipulation.js#L236:

return $.html(this[0].children);

children is an array and doesn't have a _options property. As a result, no options will be passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when there was no .load() prior html, then it's default options, won't be hard to add second argument to .html itself, everything is there.

But it this case we called .load first, so dom object has _options property.

// Yeah, it took me some time to figure out the right context with all that sticking "static" methods around. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not in the scope of this PR. I only wanted to point it out, to ensure it won't be missed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it would require more thinking, since not all the options would make effect, like decodeEntities for example, but in general it seems like good thing to have, and won't be hard to implement, since it's all there already. I can submit another one with how I see it and we can continue discussion there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be awesome; I already created #501 as a reference, but a patch would be very appreciated.

fb55 added a commit that referenced this pull request Jun 4, 2014
Fixed encoding mishaps. Adjusted tests.
@fb55 fb55 merged commit 03cbf59 into cheeriojs:master Jun 4, 2014
@fb55
Copy link
Member

fb55 commented Jun 4, 2014

Thanks!

@alexindigo
Copy link
Contributor Author

Thank you, when we can expect fresh stuff in npm? :)

@bbqsrc
Copy link

bbqsrc commented Jun 10, 2014

Quotes inside <style> tags still seem to be getting quoted however. Example case where this is a problem is font-family, often you will find fonts quoted.

@bbqsrc
Copy link

bbqsrc commented Jun 10, 2014

Oh apologies, this is indeed fixed in the latest master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants