Skip to content

Commit 75c6492

Browse files
authored
Merge pull request #36 from ktrushin/vendor_id_range
Fix isVendorAllowed() for zero vendor ID
2 parents 7bf67de + 22ddcfd commit 75c6492

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/main/java/com/iab/gdpr/consent/implementation/v1/ByteBufferBackedVendorConsent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public boolean isPurposeAllowed(Purpose purpose) {
112112
@Override
113113
public boolean isVendorAllowed(int vendorId) {
114114
final int maxVendorId = getMaxVendorId();
115-
if (vendorId < 0 || vendorId > maxVendorId) return false;
115+
if (vendorId < 1 || vendorId > maxVendorId) return false;
116116

117117
if (encodingType() == VENDOR_ENCODING_RANGE) {
118118
final boolean defaultConsent = bits.getBit(DEFAULT_CONSENT_OFFSET);

src/test/java/com/iab/gdpr/consent/implementation/v1/ByteBufferBackedVendorConsentTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ public void testBitFieldEncoding() {
237237
assertFalse(vendorConsent.isVendorAllowed(3));
238238
assertFalse(vendorConsent.isVendorAllowed(31));
239239
assertFalse(vendorConsent.isVendorAllowed(32));
240+
241+
// Vendors outside range [1, MaxVendorId] are not allowed
242+
assertFalse(vendorConsent.isVendorAllowed(-99));
243+
assertFalse(vendorConsent.isVendorAllowed(-1));
244+
assertFalse(vendorConsent.isVendorAllowed(0));
245+
assertFalse(vendorConsent.isVendorAllowed(33));
246+
assertFalse(vendorConsent.isVendorAllowed(34));
247+
assertFalse(vendorConsent.isVendorAllowed(99));
240248
}
241249

242250
@Test
@@ -275,6 +283,14 @@ public void testRangeEncodingDefaultFalse() {
275283
assertFalse(vendorConsent.isVendorAllowed(28));
276284
assertFalse(vendorConsent.isVendorAllowed(31));
277285
assertFalse(vendorConsent.isVendorAllowed(32));
286+
287+
// Vendors outside range [1, MaxVendorId] are not allowed
288+
assertFalse(vendorConsent.isVendorAllowed(-99));
289+
assertFalse(vendorConsent.isVendorAllowed(-1));
290+
assertFalse(vendorConsent.isVendorAllowed(0));
291+
assertFalse(vendorConsent.isVendorAllowed(33));
292+
assertFalse(vendorConsent.isVendorAllowed(34));
293+
assertFalse(vendorConsent.isVendorAllowed(99));
278294
}
279295

280296
@Test
@@ -313,6 +329,14 @@ public void testRangeEncodingDefaultTrue() {
313329
assertTrue(vendorConsent.isVendorAllowed(15));
314330
assertTrue(vendorConsent.isVendorAllowed(31));
315331
assertTrue(vendorConsent.isVendorAllowed(32));
332+
333+
// Vendors outside range [1, MaxVendorId] are not allowed
334+
assertFalse(vendorConsent.isVendorAllowed(-99));
335+
assertFalse(vendorConsent.isVendorAllowed(-1));
336+
assertFalse(vendorConsent.isVendorAllowed(0));
337+
assertFalse(vendorConsent.isVendorAllowed(33));
338+
assertFalse(vendorConsent.isVendorAllowed(34));
339+
assertFalse(vendorConsent.isVendorAllowed(99));
316340
}
317341

318342
@Test(expected = VendorConsentParseException.class)
@@ -548,4 +572,4 @@ public void testRealString6() {
548572
assertTrue(vendorConsent.isVendorAllowed(1000));
549573
}
550574

551-
}
575+
}

0 commit comments

Comments
 (0)