Skip to content

Bug: AbstractLazilyEncodableSection.toObj() does not trigger lazy decoding - returns default zero values #101

Description

@ssingh1002

Library version: @iabgpp/cmpapi v3.1.5

toObj() in AbstractLazilyEncodableSection does not check the decoded flag
before returning data. As a result, it returns all default/zero values instead
of the actual decoded data from the encoded string.

Root cause:
All other methods (getFieldValue, hasField, setFieldValue) correctly trigger
lazy decoding with this guard:
this.decoded || (this.segments = this.decodeSection(this.encodedString), ...)
But toObj() is missing this check entirely — it just returns this.segments as-is,
which at construction time contains only default values.

To reproduce:
const model = new GppModel();
model.decode('DBABRg~BVqqqpY');
console.log(model.getSection('usva'));

Expected behaviour:
// SharingNotice: 1, SaleOptOut: 2, SensitiveDataProcessing: [2,2,...] etc.

Actual behaviour:
// SharingNotice: 0, SaleOptOut: 0, SensitiveDataProcessing: [0,0,...] etc.

Workaround (until fixed):
Call getFieldValue() on any field first to force the section to decode, then call getSection():
model.getFieldValue('usva', 'Version'); // triggers decode
model.getSection('usva'); // now returns correct data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions