Skip to content

Commit 641ad80

Browse files
author
timmywil
committed
Attribute hooks do not need to be attached in XML docs. Fixes #9568.
1 parent 39a2f29 commit 641ad80

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/attributes.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,23 @@ jQuery.extend({
320320
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
321321

322322
// Normalize the name if needed
323-
name = notxml && jQuery.attrFix[ name ] || name;
323+
if ( notxml ) {
324+
name = jQuery.attrFix[ name ] || name;
324325

325-
hooks = jQuery.attrHooks[ name ];
326+
hooks = jQuery.attrHooks[ name ];
326327

327-
if ( !hooks ) {
328-
// Use boolHook for boolean attributes
329-
if ( rboolean.test( name ) ) {
328+
if ( !hooks ) {
329+
// Use boolHook for boolean attributes
330+
if ( rboolean.test( name ) ) {
330331

331-
hooks = boolHook;
332+
hooks = boolHook;
332333

333-
// Use formHook for forms and if the name contains certain characters
334-
} else if ( formHook && name !== "className" &&
335-
(jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) {
334+
// Use formHook for forms and if the name contains certain characters
335+
} else if ( formHook && name !== "className" &&
336+
(jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) {
336337

337-
hooks = formHook;
338+
hooks = formHook;
339+
}
338340
}
339341
}
340342

@@ -465,10 +467,11 @@ jQuery.extend({
465467
var ret, hooks,
466468
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
467469

468-
// Try to normalize/fix the name
469-
name = notxml && jQuery.propFix[ name ] || name;
470-
471-
hooks = jQuery.propHooks[ name ];
470+
if ( notxml ) {
471+
// Fix name and attach hooks
472+
name = jQuery.propFix[ name ] || name;
473+
hooks = jQuery.propHooks[ name ];
474+
}
472475

473476
if ( value !== undefined ) {
474477
if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {

test/data/dashboard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<dashboard>
33
<locations class="foo">
4-
<location for="bar">
4+
<location for="bar" checked="different">
55
<infowindowtab>
66
<tab title="Location"><![CDATA[blabla]]></tab>
77
<tab title="Users"><![CDATA[blublu]]></tab>

test/unit/attributes.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ test("attr(String)", function() {
132132

133133
if ( !isLocal ) {
134134
test("attr(String) in XML Files", function() {
135-
expect(2);
135+
expect(3);
136136
stop();
137137
jQuery.get("data/dashboard.xml", function( xml ) {
138-
equals( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
139-
equals( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
138+
equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
139+
equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
140+
equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
140141
start();
141142
});
142143
});

0 commit comments

Comments
 (0)