@@ -249,12 +249,7 @@ class SignedXml {
249
249
}
250
250
251
251
validateReferences ( doc ) {
252
- for ( const r in this . references ) {
253
- if ( ! this . references . hasOwnProperty ( r ) ) {
254
- continue ;
255
- }
256
-
257
- const ref = this . references [ r ] ;
252
+ for ( const ref of this . references ) {
258
253
let elemXpath ;
259
254
const uri = ref . uri [ 0 ] === "#" ? ref . uri . substring ( 1 ) : ref . uri ;
260
255
let elem = [ ] ;
@@ -266,12 +261,8 @@ class SignedXml {
266
261
throw new Error ( "Cannot validate a uri with quotes inside it" ) ;
267
262
} else {
268
263
let num_elements_for_id = 0 ;
269
- for ( const index in this . idAttributes ) {
270
- if ( ! this . idAttributes . hasOwnProperty ( index ) ) {
271
- continue ;
272
- }
273
- const tmp_elemXpath =
274
- "//*[@*[local-name(.)='" + this . idAttributes [ index ] + "']='" + uri + "']" ;
264
+ for ( const attr of this . idAttributes ) {
265
+ const tmp_elemXpath = `//*[@*[local-name(.)='${ attr } ']='${ uri } ']` ;
275
266
const tmp_elem = xpath . select ( tmp_elemXpath , doc ) ;
276
267
num_elements_for_id += tmp_elem . length ;
277
268
if ( tmp_elem . length > 0 ) {
@@ -352,12 +343,8 @@ class SignedXml {
352
343
throw new Error ( "could not find any Reference elements" ) ;
353
344
}
354
345
355
- for ( const i in references ) {
356
- if ( ! references . hasOwnProperty ( i ) ) {
357
- continue ;
358
- }
359
-
360
- this . loadReference ( references [ i ] ) ;
346
+ for ( const reference of references ) {
347
+ this . loadReference ( reference ) ;
361
348
}
362
349
363
350
this . signatureValue = utils
@@ -400,15 +387,12 @@ class SignedXml {
400
387
if ( nodes . length !== 0 ) {
401
388
const transformsNode = nodes [ 0 ] ;
402
389
const transformsAll = utils . findChilds ( transformsNode , "Transform" ) ;
403
- for ( const t in transformsAll ) {
404
- if ( ! transformsAll . hasOwnProperty ( t ) ) {
405
- continue ;
406
- }
407
-
408
- trans = transformsAll [ t ] ;
390
+ for ( const t of transformsAll ) {
391
+ trans = t ;
409
392
transforms . push ( utils . findAttr ( trans , "Algorithm" ) . value ) ;
410
393
}
411
394
395
+ // This is a little strange, we are looking for children of the last child of `transformsNode`
412
396
const inclusiveNamespaces = utils . findChilds ( trans , "InclusiveNamespaces" ) ;
413
397
if ( inclusiveNamespaces . length > 0 ) {
414
398
//Should really only be one prefix list, but maybe there's some circumstances where more than one to lets handle it
@@ -676,12 +660,7 @@ class SignedXml {
676
660
prefix = prefix || "" ;
677
661
prefix = prefix ? prefix + ":" : prefix ;
678
662
679
- for ( const n in this . references ) {
680
- if ( ! this . references . hasOwnProperty ( n ) ) {
681
- continue ;
682
- }
683
-
684
- const ref = this . references [ n ] ;
663
+ for ( const ref of this . references ) {
685
664
const nodes = xpath . selectWithResolver ( ref . xpath , doc , this . namespaceResolver ) ;
686
665
687
666
if ( nodes . length === 0 ) {
@@ -690,12 +669,7 @@ class SignedXml {
690
669
) ;
691
670
}
692
671
693
- for ( const h in nodes ) {
694
- if ( ! nodes . hasOwnProperty ( h ) ) {
695
- continue ;
696
- }
697
-
698
- const node = nodes [ h ] ;
672
+ for ( const node of nodes ) {
699
673
if ( ref . isEmptyUri ) {
700
674
res += "<" + prefix + 'Reference URI="">' ;
701
675
} else {
@@ -704,12 +678,7 @@ class SignedXml {
704
678
res += "<" + prefix + 'Reference URI="#' + id + '">' ;
705
679
}
706
680
res += "<" + prefix + "Transforms>" ;
707
- for ( const t in ref . transforms ) {
708
- if ( ! ref . transforms . hasOwnProperty ( t ) ) {
709
- continue ;
710
- }
711
-
712
- const trans = ref . transforms [ t ] ;
681
+ for ( const trans of ref . transforms ) {
713
682
const transform = this . findCanonicalizationAlgorithm ( trans ) ;
714
683
res += "<" + prefix + 'Transform Algorithm="' + transform . getAlgorithmName ( ) + '"' ;
715
684
if ( ref . inclusiveNamespacesPrefixList ) {
@@ -761,12 +730,8 @@ class SignedXml {
761
730
762
731
let canonXml = node . cloneNode ( true ) ; // Deep clone
763
732
764
- for ( const t in transforms ) {
765
- if ( ! transforms . hasOwnProperty ( t ) ) {
766
- continue ;
767
- }
768
-
769
- const transform = this . findCanonicalizationAlgorithm ( transforms [ t ] ) ;
733
+ Object . values ( transforms ) . forEach ( ( transformName ) => {
734
+ const transform = this . findCanonicalizationAlgorithm ( transformName ) ;
770
735
canonXml = transform . process ( canonXml , options ) ;
771
736
//TODO: currently transform.process may return either Node or String value (enveloped transformation returns Node, exclusive-canonicalization returns String).
772
737
//This either needs to be more explicit in the API, or all should return the same.
@@ -775,7 +740,8 @@ class SignedXml {
775
740
//enveloped transformation returns Node since if it would return String consider this case:
776
741
//<x xmlns:p='ns'><p:y/></x>
777
742
//if only y is the node to sign then a string would be <p:y/> without the definition of the p namespace. probably xmldom toString() should have added it.
778
- }
743
+ } ) ;
744
+
779
745
return canonXml . toString ( ) ;
780
746
}
781
747
@@ -793,16 +759,10 @@ class SignedXml {
793
759
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
794
760
) ;
795
761
} else {
796
- for ( const index in this . idAttributes ) {
797
- if ( ! this . idAttributes . hasOwnProperty ( index ) ) {
798
- continue ;
799
- }
800
-
801
- attr = utils . findAttr ( node , this . idAttributes [ index ] , null ) ;
802
- if ( attr ) {
803
- break ;
804
- }
805
- }
762
+ Object . values ( this . idAttributes ) . some ( ( idAttribute ) => {
763
+ attr = utils . findAttr ( node , idAttribute , null ) ;
764
+ return ! ! attr ; // This will break the loop as soon as a truthy attr is found.
765
+ } ) ;
806
766
}
807
767
808
768
if ( attr ) {
0 commit comments