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
795583d2
Commit
795583d2
authored
Nov 07, 2011
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #10690. Make sure `.isNumeric()` can't get a `Date`.
Also add tests for custom objects with a `.toString()` method.
parent
13aa8458
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
core.js
src/core.js
+1
-1
core.js
test/unit/core.js
+15
-3
No files found.
src/core.js
View file @
795583d2
...
@@ -485,7 +485,7 @@ jQuery.extend({
...
@@ -485,7 +485,7 @@ jQuery.extend({
},
},
isNumeric
:
function
(
obj
)
{
isNumeric
:
function
(
obj
)
{
return
obj
!=
null
&&
rdigit
.
test
(
obj
)
&&
!
isNaN
(
obj
);
return
!
isNaN
(
parseFloat
(
obj
)
)
&&
isFinite
(
obj
);
},
},
type
:
function
(
obj
)
{
type
:
function
(
obj
)
{
...
...
test/unit/core.js
View file @
795583d2
...
@@ -455,9 +455,17 @@ test("isFunction", function() {
...
@@ -455,9 +455,17 @@ test("isFunction", function() {
});
});
test
(
"isNumeric"
,
function
()
{
test
(
"isNumeric"
,
function
()
{
expect
(
33
);
expect
(
37
);
var
t
=
jQuery
.
isNumeric
;
var
t
=
jQuery
.
isNumeric
,
Traditionalists
=
function
(
n
)
{
this
.
value
=
n
;
this
.
toString
=
function
(){
return
String
(
this
.
value
);
};
},
answer
=
new
Traditionalists
(
"42"
),
rong
=
new
Traditionalists
(
"Devo"
);
ok
(
t
(
"-10"
),
"Negative integer string"
);
ok
(
t
(
"-10"
),
"Negative integer string"
);
ok
(
t
(
"0"
),
"Zero string"
);
ok
(
t
(
"0"
),
"Zero string"
);
...
@@ -475,6 +483,7 @@ test( "isNumeric", function() {
...
@@ -475,6 +483,7 @@ test( "isNumeric", function() {
ok
(
t
(
3.1415
),
"Positive floating point number"
);
ok
(
t
(
3.1415
),
"Positive floating point number"
);
ok
(
t
(
8
e5
),
"Exponential notation"
);
ok
(
t
(
8
e5
),
"Exponential notation"
);
ok
(
t
(
"123e-2"
),
"Exponential notation string"
);
ok
(
t
(
"123e-2"
),
"Exponential notation string"
);
ok
(
t
(
answer
),
"Custom .toString returning number"
);
equal
(
t
(
""
),
false
,
"Empty string"
);
equal
(
t
(
""
),
false
,
"Empty string"
);
equal
(
t
(
" "
),
false
,
"Whitespace characters string"
);
equal
(
t
(
" "
),
false
,
"Whitespace characters string"
);
equal
(
t
(
"
\
t
\
t"
),
false
,
"Tab characters string"
);
equal
(
t
(
"
\
t
\
t"
),
false
,
"Tab characters string"
);
...
@@ -490,8 +499,11 @@ test( "isNumeric", function() {
...
@@ -490,8 +499,11 @@ test( "isNumeric", function() {
equal
(
t
(
Infinity
),
false
,
"Infinity primitive"
);
equal
(
t
(
Infinity
),
false
,
"Infinity primitive"
);
equal
(
t
(
Number
.
POSITIVE_INFINITY
),
false
,
"Positive Infinity"
);
equal
(
t
(
Number
.
POSITIVE_INFINITY
),
false
,
"Positive Infinity"
);
equal
(
t
(
Number
.
NEGATIVE_INFINITY
),
false
,
"Negative Infinity"
);
equal
(
t
(
Number
.
NEGATIVE_INFINITY
),
false
,
"Negative Infinity"
);
equal
(
t
(
rong
),
false
,
"Custom .toString returning non-number"
);
equal
(
t
({}),
false
,
"Empty object"
);
equal
(
t
({}),
false
,
"Empty object"
);
equal
(
t
(
function
(){}
),
false
,
"Instance of a function"
);
equal
(
t
(
function
(){}
),
false
,
"Instance of a function"
);
equal
(
t
(
new
Date
),
false
,
"Instance of a Date"
);
equal
(
t
(
function
(){}
),
false
,
"Instance of a function"
);
});
});
test
(
"isXMLDoc - HTML"
,
function
()
{
test
(
"isXMLDoc - HTML"
,
function
()
{
...
...
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