-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Clone input nodes when inserting over a set #574
Conversation
*/ | ||
exports.isHtml = function(str) { | ||
// Faster than running regex, if str starts with `<` and ends with `>`, assume it's HTML | ||
if (str.charAt(0) === '<' && str.charAt(str.length - 1) === '>' && str.length >= 3) return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could replace str.length >= 3
with str !== '<>'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I'm not sure that would be an improvement since it duplicates information. The preceeding conditions already checked for the character values, after all.
If you're motivated by optimization, I wouldn't necessarily object (this is used on pretty hot code path, after all). In that case, though, we'll have to microbenchmark and consider a bunch of other alternatives (str.length > 2
comes to mind, along with comparing the relative speed of charAt
and the array subscripting operator).
@davidchambers I just realized that it was coimpletely unecessary to move the (In case you're curious: I noticed this bug while working on another feature branch. I cherry-picked that commit onto |
Why is the last element in a set treated differently? |
@davidchambers I want to match jQuery's behavior. From the API documentation on
I can only guess at the rationale. Here goes: When calling, for instance, Again, this is completely conjecture on my part, since the API documentation doesn't really cover motivation for design decisions. What do you think? |
That makes sense, @jugglinmike! Thanks for the explanation. :) |
Needs a rebase, LGTM, though. |
8340187
to
56fbefb
Compare
This patch increases parity with jQuery, specifically in cases where manipulation methods are called with existing nodes on sets containing more than one element. In such cases, the provided node should be cloned prior to insertion (excepting the final element in the set, where the original node should be inserted).
56fbefb
to
466e34a
Compare
@fb55 I've updated this one, too |
Clone input nodes when inserting over a set
And merged. |
Yessss |
:D |
I noticed this bug while wrapping up gh-558 (c'mon that's funny). I think the changeset ended up being a little ugly, so please don't hesitate to offer suggestions for refactoring!
Commit message: