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
27b22f4e
Commit
27b22f4e
authored
Nov 11, 2013
by
hongymagic
Committed by
Richard Gibson
Nov 15, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #14503: Cast to string before setting XHR header. Close gh-1427.
parent
5f325b1b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
xhr.js
src/ajax/xhr.js
+9
-1
headers.php
test/data/headers.php
+6
-1
ajax.js
test/unit/ajax.js
+13
-5
No files found.
src/ajax/xhr.js
View file @
27b22f4e
...
@@ -74,7 +74,15 @@ if ( xhrSupported ) {
...
@@ -74,7 +74,15 @@ if ( xhrSupported ) {
// Set headers
// Set headers
for
(
i
in
headers
)
{
for
(
i
in
headers
)
{
xhr
.
setRequestHeader
(
i
,
headers
[
i
]
);
// Support: IE<9
// IE's ActiveXObject throws a 'Type Mismatch' exception when setting
// request header to a null-value.
//
// To keep consistent with other XHR implementations, cast the value
// to string and ignore `undefined`.
if
(
headers
[
i
]
!==
undefined
)
{
xhr
.
setRequestHeader
(
i
,
headers
[
i
]
+
""
);
}
}
}
// Do send the request
// Do send the request
...
...
test/data/headers.php
View file @
27b22f4e
...
@@ -14,5 +14,10 @@ foreach( $_SERVER as $key => $value ) {
...
@@ -14,5 +14,10 @@ foreach( $_SERVER as $key => $value ) {
}
}
foreach
(
explode
(
"_"
,
$_GET
[
"keys"
]
)
as
$key
)
{
foreach
(
explode
(
"_"
,
$_GET
[
"keys"
]
)
as
$key
)
{
echo
"
$key
: "
.
@
$headers
[
strtoupper
(
$key
)
]
.
"
\n
"
;
// Only echo if key exists in the header
if
(
isset
(
$headers
[
strtoupper
(
$key
)
]
)
)
{
echo
"
$key
: "
.
@
$headers
[
strtoupper
(
$key
)
]
.
"
\n
"
;
}
}
}
test/unit/ajax.js
View file @
27b22f4e
...
@@ -177,17 +177,24 @@ module( "ajax", {
...
@@ -177,17 +177,24 @@ module( "ajax", {
});
});
});
});
ajaxTest
(
"jQuery.ajax() - headers"
,
4
,
{
ajaxTest
(
"jQuery.ajax() - headers"
,
5
,
{
setup
:
function
()
{
setup
:
function
()
{
jQuery
(
document
).
ajaxSend
(
function
(
evt
,
xhr
)
{
jQuery
(
document
).
ajaxSend
(
function
(
evt
,
xhr
)
{
xhr
.
setRequestHeader
(
"ajax-send"
,
"test"
);
xhr
.
setRequestHeader
(
"ajax-send"
,
"test"
);
});
});
},
},
url
:
url
(
"data/headers.php?keys=siMPle_SometHing-elsE_OthEr_ajax-send"
),
url
:
url
(
"data/headers.php?keys=siMPle_SometHing-elsE_OthEr_
Nullable_undefined_Empty_
ajax-send"
),
headers
:
{
headers
:
{
"siMPle"
:
"value"
,
"siMPle"
:
"value"
,
"SometHing-elsE"
:
"other value"
,
"SometHing-elsE"
:
"other value"
,
"OthEr"
:
"something else"
"OthEr"
:
"something else"
,
"Nullable"
:
null
,
"undefined"
:
undefined
,
// Support: Firefox
// Not all browsers allow empty-string headers
// https://bugzilla.mozilla.org/show_bug.cgi?id=815299
//"Empty": ""
},
},
success
:
function
(
data
,
_
,
xhr
)
{
success
:
function
(
data
,
_
,
xhr
)
{
var
i
,
emptyHeader
,
var
i
,
emptyHeader
,
...
@@ -196,12 +203,13 @@ module( "ajax", {
...
@@ -196,12 +203,13 @@ module( "ajax", {
}),
}),
tmp
=
[];
tmp
=
[];
for
(
i
in
requestHeaders
)
{
for
(
i
in
requestHeaders
)
{
tmp
.
push
(
i
,
": "
,
requestHeaders
[
i
],
"
\n
"
);
tmp
.
push
(
i
,
": "
,
requestHeaders
[
i
]
+
""
,
"
\n
"
);
}
}
tmp
=
tmp
.
join
(
""
);
tmp
=
tmp
.
join
(
""
);
strictEqual
(
data
,
tmp
,
"Headers were sent"
);
strictEqual
(
data
,
tmp
,
"Headers were sent"
);
strictEqual
(
xhr
.
getResponseHeader
(
"Sample-Header"
),
"Hello World"
,
"Sample header received"
);
strictEqual
(
xhr
.
getResponseHeader
(
"Sample-Header"
),
"Hello World"
,
"Sample header received"
);
ok
(
data
.
indexOf
(
"undefined"
)
<
0
,
"Undefined header value was not sent"
);
emptyHeader
=
xhr
.
getResponseHeader
(
"Empty-Header"
);
emptyHeader
=
xhr
.
getResponseHeader
(
"Empty-Header"
);
if
(
emptyHeader
===
null
)
{
if
(
emptyHeader
===
null
)
{
...
@@ -238,7 +246,7 @@ module( "ajax", {
...
@@ -238,7 +246,7 @@ module( "ajax", {
url
:
url
(
"data/headers.php?keys=content-type"
),
url
:
url
(
"data/headers.php?keys=content-type"
),
contentType
:
false
,
contentType
:
false
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
strictEqual
(
data
,
"
content-type:
\n
"
,
"Test content-type is not sent when options.contentType===false"
);
strictEqual
(
data
,
""
,
"Test content-type is not sent when options.contentType===false"
);
}
}
}
}
]);
]);
...
...
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