File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ export default class HTMLElement extends Node {
511
511
}
512
512
513
513
public hasAttribute ( key : string ) {
514
- return key in this . attrs ;
514
+ return key . toLowerCase ( ) in this . attrs ;
515
515
}
516
516
517
517
/**
@@ -531,10 +531,18 @@ export default class HTMLElement extends Node {
531
531
if ( arguments . length < 2 ) {
532
532
throw new Error ( 'Failed to execute \'setAttribute\' on \'Element\'' ) ;
533
533
}
534
+ const k2 = key . toLowerCase ( ) ;
534
535
const attrs = this . rawAttributes ;
536
+ for ( const k in attrs ) {
537
+ if ( k . toLowerCase ( ) === k2 ) {
538
+ key = k ;
539
+ break ;
540
+ }
541
+ }
535
542
attrs [ key ] = String ( value ) ;
543
+ // update this.attrs
536
544
if ( this . _attrs ) {
537
- this . _attrs [ key ] = decode ( attrs [ key ] ) ;
545
+ this . _attrs [ k2 ] = decode ( attrs [ key ] ) ;
538
546
}
539
547
// Update rawString
540
548
this . rawAttrs = Object . keys ( attrs ) . map ( ( name ) => {
Original file line number Diff line number Diff line change @@ -14,4 +14,20 @@ describe('getAttribute should be case insensitive', function () {
14
14
const root = parse ( '<a onClick="listener()"></a>' ) ;
15
15
root . firstChild . getAttribute ( 'onclick' ) . should . eql ( 'listener()' ) ;
16
16
} ) ;
17
+ it ( 'set attribute in lowercase' , function ( ) {
18
+ const root = parse ( '<a onClick="listener()"></a>' ) ;
19
+ const a = root . firstChild ;
20
+ a . setAttribute ( 'onclick' , 'listener2' ) ;
21
+ a . getAttribute ( 'onclick' ) . should . eql ( 'listener2' ) ;
22
+ root . toString ( ) . should . eql ( '<a onClick="listener2"></a>' ) ;
23
+ } ) ;
24
+ it ( 'add attributes' , function ( ) {
25
+ const root = parse ( '<a onClick="listener()"></a>' ) ;
26
+ const a = root . firstChild ;
27
+ a . setAttribute ( 'onclick' , 'listener2' ) ;
28
+ a . getAttribute ( 'onclick' ) . should . eql ( 'listener2' ) ;
29
+ a . setAttribute ( 'onDoubleClick' , 'listener3' ) ;
30
+ a . getAttribute ( 'onDoubleClick' ) . should . eql ( 'listener3' ) ;
31
+ root . toString ( ) . should . eql ( '<a onClick="listener2" onDoubleClick="listener3"></a>' ) ;
32
+ } ) ;
17
33
} ) ;
You can’t perform that action at this time.
0 commit comments