@@ -482,19 +482,27 @@ public boolean includes(MediaType other) {
482
482
return true ;
483
483
}
484
484
else if (this .type .equals (other .type )) {
485
- if (this .subtype .equals (other .subtype ) || this . isWildcardSubtype () ) {
485
+ if (this .subtype .equals (other .subtype )) {
486
486
return true ;
487
487
}
488
- // application/*+xml includes application/soap+xml
489
- int thisPlusIdx = this .subtype .indexOf ('+' );
490
- int otherPlusIdx = other .subtype .indexOf ('+' );
491
- if (thisPlusIdx != -1 && otherPlusIdx != -1 ) {
492
- String thisSubtypeNoSuffix = this .subtype .substring (0 , thisPlusIdx );
493
- String thisSubtypeSuffix = this .subtype .substring (thisPlusIdx + 1 );
494
- String otherSubtypeSuffix = other .subtype .substring (otherPlusIdx + 1 );
495
- if (thisSubtypeSuffix .equals (otherSubtypeSuffix ) && WILDCARD_TYPE .equals (thisSubtypeNoSuffix )) {
488
+ if (this .isWildcardSubtype ()) {
489
+ // wildcard with suffix, e.g. application/*+xml
490
+ int thisPlusIdx = this .subtype .indexOf ('+' );
491
+ if (thisPlusIdx == -1 ) {
496
492
return true ;
497
493
}
494
+ else {
495
+ // application/*+xml includes application/soap+xml
496
+ int otherPlusIdx = other .subtype .indexOf ('+' );
497
+ if (otherPlusIdx != -1 ) {
498
+ String thisSubtypeNoSuffix = this .subtype .substring (0 , thisPlusIdx );
499
+ String thisSubtypeSuffix = this .subtype .substring (thisPlusIdx + 1 );
500
+ String otherSubtypeSuffix = other .subtype .substring (otherPlusIdx + 1 );
501
+ if (thisSubtypeSuffix .equals (otherSubtypeSuffix ) && WILDCARD_TYPE .equals (thisSubtypeNoSuffix )) {
502
+ return true ;
503
+ }
504
+ }
505
+ }
498
506
}
499
507
}
500
508
return false ;
@@ -515,23 +523,30 @@ public boolean isCompatibleWith(MediaType other) {
515
523
return true ;
516
524
}
517
525
else if (this .type .equals (other .type )) {
518
- if (this .subtype .equals (other .subtype ) || this . isWildcardSubtype () || other . isWildcardSubtype () ) {
526
+ if (this .subtype .equals (other .subtype )) {
519
527
return true ;
520
528
}
521
- // application/*+xml is compatible with application/soap+xml, and vice-versa
522
- int thisPlusIdx = this .subtype .indexOf ('+' );
523
- int otherPlusIdx = other .subtype .indexOf ('+' );
524
- if (thisPlusIdx != -1 && otherPlusIdx != -1 ) {
525
- String thisSubtypeNoSuffix = this .subtype .substring (0 , thisPlusIdx );
526
- String otherSubtypeNoSuffix = other .subtype .substring (0 , otherPlusIdx );
527
-
528
- String thisSubtypeSuffix = this .subtype .substring (thisPlusIdx + 1 );
529
- String otherSubtypeSuffix = other .subtype .substring (otherPlusIdx + 1 );
530
-
531
- if (thisSubtypeSuffix .equals (otherSubtypeSuffix ) &&
532
- (WILDCARD_TYPE .equals (thisSubtypeNoSuffix ) || WILDCARD_TYPE .equals (otherSubtypeNoSuffix ))) {
529
+ // wildcard with suffix? e.g. application/*+xml
530
+ if (this .isWildcardSubtype () || other .isWildcardSubtype ()) {
531
+
532
+ int thisPlusIdx = this .subtype .indexOf ('+' );
533
+ int otherPlusIdx = other .subtype .indexOf ('+' );
534
+
535
+ if (thisPlusIdx == -1 && otherPlusIdx == -1 ) {
533
536
return true ;
534
537
}
538
+ else if (thisPlusIdx != -1 && otherPlusIdx != -1 ) {
539
+ String thisSubtypeNoSuffix = this .subtype .substring (0 , thisPlusIdx );
540
+ String otherSubtypeNoSuffix = other .subtype .substring (0 , otherPlusIdx );
541
+
542
+ String thisSubtypeSuffix = this .subtype .substring (thisPlusIdx + 1 );
543
+ String otherSubtypeSuffix = other .subtype .substring (otherPlusIdx + 1 );
544
+
545
+ if (thisSubtypeSuffix .equals (otherSubtypeSuffix ) &&
546
+ (WILDCARD_TYPE .equals (thisSubtypeNoSuffix ) || WILDCARD_TYPE .equals (otherSubtypeNoSuffix ))) {
547
+ return true ;
548
+ }
549
+ }
535
550
}
536
551
}
537
552
return false ;
0 commit comments