Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
812c6087
Commit
812c6087
authored
Oct 24, 2012
by
Rick Waldron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Brute force property removal when removeData([a,b,c]). Fixes #12786
Signed-off-by:
Rick Waldron
<
waldron.rick@gmail.com
>
parent
2eff7fe7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
data.js
src/data.js
+8
-0
data.js
test/unit/data.js
+70
-0
No files found.
src/data.js
View file @
812c6087
...
@@ -136,6 +136,14 @@ function internalRemoveData( elem, name, pvt /* For internal use only */ ){
...
@@ -136,6 +136,14 @@ function internalRemoveData( elem, name, pvt /* For internal use only */ ){
name
=
name
.
split
(
" "
);
name
=
name
.
split
(
" "
);
}
}
}
}
}
else
{
// If "name" is an array of keys...
// When data is initially created, via ("key", "val") signature,
// keys will be converted to camelCase.
// Since there is no way to tell _how_ a key was added, remove
// both plain key and camelCase key. #12786
// This will only penalize the array argument path.
name
=
name
.
concat
(
jQuery
.
map
(
name
,
jQuery
.
camelCase
)
);
}
}
for
(
i
=
0
,
l
=
name
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
name
.
length
;
i
<
l
;
i
++
)
{
...
...
test/unit/data.js
View file @
812c6087
...
@@ -621,6 +621,76 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
...
@@ -621,6 +621,76 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
});
});
});
});
test
(
"jQuery.fn.removeData supports interoperable removal of hyphenated properties via array (#12786)"
,
function
()
{
expect
(
10
);
var
div
,
plain
,
datas
,
keys
;
div
=
jQuery
(
"<div/>"
,
{
id
:
"test12786"
}).
appendTo
(
"#qunit-fixture"
),
datas
=
{
"non-empty"
:
"a string"
,
"empty-string"
:
""
,
"one-value"
:
1
,
"zero-value"
:
0
,
"an-array"
:
[],
"an-object"
:
{},
"bool-true"
:
true
,
"bool-false"
:
false
,
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
"some-json"
:
"{
\"
foo
\"
:
\"
bar
\"
}"
};
keys
=
jQuery
.
map
(
datas
,
function
(
_
,
key
)
{
return
key
;
});
// "keys" is an array that looks like this:
// [
// "non-empty", "empty-string", "one-value", "zero-value",
// "an-array", "an-object", "bool-true", "bool-false", "some-json"
// ]
div
.
data
(
datas
);
deepEqual
(
div
.
data
(),
datas
,
"div.data() returns an object whose values match those of datas (div)"
);
div
.
removeData
(
keys
.
hyphen
);
ok
(
jQuery
.
isEmptyObject
(
div
.
data
()
),
"After removal by array of hyphenated keys, div.data() returns an object with no properties (div)"
);
div
.
data
(
"a-a"
,
1
);
div
.
data
(
"b-b"
,
2
);
deepEqual
(
div
.
data
(
"a-a"
),
1
,
"div.data('a-a') returns value that matches the manually set value (div)"
);
deepEqual
(
div
.
data
(
"b-b"
),
2
,
"div.data('b-b') returns value that matches the manually set value (div)"
);
div
.
removeData
([
"a-a"
,
"b-b"
]);
ok
(
jQuery
.
isEmptyObject
(
div
.
data
()
),
"After removal by array of hyphenated keys, div.data() returns an object with no properties (div)"
);
plain
=
jQuery
({});
plain
.
data
(
datas
);
deepEqual
(
plain
.
data
(),
datas
,
"plain.data() returns an object whose values match those of datas (plain)"
);
plain
.
removeData
(
keys
);
ok
(
jQuery
.
isEmptyObject
(
plain
.
data
()
),
"After removal by array of hyphenated keys, plain.data() returns an object with no properties (plain)"
);
plain
=
jQuery
({});
plain
.
data
(
"a-a"
,
1
);
plain
.
data
(
"b-b"
,
2
);
deepEqual
(
plain
.
data
(
"a-a"
),
1
,
"plain.data('a-a') returns value that matches the manually set value (plain)"
);
deepEqual
(
plain
.
data
(
"b-b"
),
2
,
"plain.data('b-b') returns value that matches the manually set value (plain)"
);
plain
.
removeData
([
"a-a"
,
"b-b"
]);
ok
(
jQuery
.
isEmptyObject
(
plain
.
data
()
),
"After removal by array of hyphenated keys, plain.data() returns an object with no properties (plain)"
);
});
// Test originally by Moschel
// Test originally by Moschel
test
(
"Triggering the removeData should not throw exceptions. (#10080)"
,
function
()
{
test
(
"Triggering the removeData should not throw exceptions. (#10080)"
,
function
()
{
expect
(
1
);
expect
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment