Add TCF 2.3 support: Disclosed Vendors segment parsing#1
Open
Add TCF 2.3 support: Disclosed Vendors segment parsing#1
Conversation
2c03bed to
20b9379
Compare
DisclosedVendors segment parsing
20b9379 to
5000b87
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements support for the TCF 2.3 Disclosed Vendors segment, which becomes mandatory on March 1st, 2025. Given the short timeline for compliance, I extended the existing
ConsentMetadatastructure to parse and store disclosed vendors data, reusing the establishedparseBitField()andparseRangeSection()patterns. The implementation fully supports both BitField and RangeSection encoding modes as specified in the TCF 2.3 standard. While this approach delivers quickly and maintains backward compatibility, future refactoring should separate segment parsing concerns for better modularity.Changes
VendorDisclosed(id),VendorDisclosedMaxVendorId(), andHasDisclosedVendors()methods to theVendorConsentsinterfacedisclosed_vendors.goto parse the Disclosed Vendors segment (segment type 1) with full support for both BitField (IsRangeEncoding=0) and RangeSection (IsRangeEncoding=1) encoding modesparseWithDisclosedVendors()to iterate through consent string segments and detect the disclosed vendors segment by typeConsentMetadatastruct withdisclosedVendorsandhasDisclosedVendorsfieldsVendorDisclosed()returnsfalse)parseRangeSection()to calculate minimum required bytes dynamically instead of using a hardcoded 31-byte check, enabling proper segment parsingTesting
disclosed_vendors_test.gofor BitField encodingTestSegmentsInAnyOrder)Technical Details
Segments after the core string can appear in any order, so the parser checks each segment's type before processing. The implementation correctly handles both encoding modes by checking bit 19 and delegating to either
parseBitField()orparseRangeSection()accordingly.Future Considerations
The current implementation tightly couples segment parsing within
ConsentMetadata. As the TCF spec evolves and additional segments are needed (e.g., Publisher TC), consider refactoring to a cleaner segment-based architecture where each segment type has its own parser and data structure.