Ticket #6779 (closed bug: fixed)
Dom Manipulation fails if added text happens to match Object method
| Reported by: | cscott | Owned by: | dmethvin |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | manipulation | Version: | 1.4.4 |
| Keywords: | dommanip cache | Cc: | |
| Blocking: | Blocked by: | #5876 |
Description
When you try to add the text "hasOwnProperty", for example, the dom manipulation cache "finds" hasOwnProperty and tries to add a *function* to the DOM. This also holds for any other methods of Object.
The attached patch fixes the problem, by using hasOwnProperty to ensure that the cache match isn't actually an Object method. (We also need to ensure that hasOwnProperty isn't cacheable.)
Attachments
Change History
Changed 3 years ago by cscott
-
attachment
0001-Avoid-problems-when-adding-text-which-happens-to-mat.patch
added
comment:1 Changed 3 years ago by cscott
Patch also in github as: http://github.com/cscott/jquery/commit/7dbc01ae248b1abd8751fdff1ec0891b6ba1d5c6
comment:2 Changed 3 years ago by rwaldron
- Owner set to cscott
- Priority set to undecided
- Status changed from new to pending
Please provide a reduced jsFiddle test case, thanks!
comment:3 Changed 2 years ago by dmethvin
http://jsfiddle.net/dmethvin/SdCg8/6/ Test case
comment:4 Changed 2 years ago by dmethvin
snover suggested we just not cache strings that have no html, that would fix the problem with a simple test for '<'.
comment:5 Changed 2 years ago by snover
- Priority changed from undecided to high
- Status changed from pending to open
- Version changed from 1.4.2 to 1.4.4
- Blocked by 5876 added
- Milestone 1.4.3 deleted
Beyond just not testing for strings with no HTML, I suggested to only cache strings where the first character is a <.
comment:7 Changed 2 years ago by dmethvin
- Owner changed from cscott to dmethvin
- Status changed from open to assigned
comment:9 Changed 2 years ago by Dave Methvin
- Status changed from assigned to closed
- Resolution set to fixed
Don't cache non-html strings in buildFragment to avoid possible collision with the names of Object methods like toString. Also makes the unit tests 0.5% to 8% faster. Fixes #6779.
Changeset: 5fd21fc02bda43d4e31bcf2d5b55b918a9190a7f
comment:10 Changed 2 years ago by Dave Methvin
Don't cache non-html strings in buildFragment to avoid possible collision with the names of Object methods like toString. Also makes the unit tests 0.5% to 8% faster. Fixes #6779.
Changeset: 5fd21fc02bda43d4e31bcf2d5b55b918a9190a7f
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Patch to fix the problem.