Fix Column.string returning raw bytes for non-text column types#105
Open
ericraio wants to merge 1 commit into
Open
Fix Column.string returning raw bytes for non-text column types#105ericraio wants to merge 1 commit into
ericraio wants to merge 1 commit into
Conversation
Motivation: The DataStax C driver's cass_value_get_string has no type checking - it calls as_string_ref() and returns CASS_OK for any non-null value, regardless of the column's actual CQL type. The Swift toString() helper called this unconditionally, meaning Column.string appeared to succeed for int, bigint, blob, uuid, boolean, float, double, UDT, and frozen collection columns, returning their raw binary serialization decoded as lossy UTF-8. This caused callers that try Column.string before falling back to typed accessors to silently receive binary garbage instead of nil, breaking display layers for frozen UDTs and complex types. Modifications: - In toString(), call cass_value_type first and return nil early for any type that is not ASCII, TEXT, or VARCHAR. - Replace String(decoding:as:UTF8.self) (non-failable, silently replaces invalid UTF-8 with U+FFFD) with String(bytes:encoding:) (failable, returns nil for invalid UTF-8). - Add DataTests.swift with integration tests verifying Column.string returns a value for text-typed columns and nil for all other types. Result: Column.string now returns nil for non-text columns, matching the documented semantics. Typed accessors on those columns continue to work correctly. Callers that use Column.string as a fallback for unknown types will correctly fall through to bytes or other representations.
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.
Fix Column.string returning raw bytes for non-text column types
Motivation:
The DataStax C driver's
cass_value_get_stringhas no type checking - it callsas_string_ref()and returnsCASS_OKfor any non-null value, regardless of the column's actual CQL type.The Swift
toString()helper called this unconditionally, meaningColumn.stringappeared to succeed forint,bigint,blob,uuid,boolean,float,double,UDTand frozen collection columns, returning their raw binary serialization decoded as lossy UTF-8.This caused callers that try
Column.stringbefore falling back to typed accessors to silently receive binary garbage instead of nil, breaking display layers for frozen UDTs and complex types.Modifications:
toString(),call cass_value_typefirst and return nil early for any type that is notASCII, TEXT, orVARCHAR.String(decoding:as:UTF8.self)(non-failable, silently replaces invalid UTF-8 with U+FFFD) withString(bytes:encoding:)(failable, returns nil for invalid UTF-8).DataTests.swiftwith integration tests verifyingColumn.stringreturns a value for text-typed columns and nil for all other types.Result:
Column.stringnow returns nil for non-text columns, matching the documented semantics. Typed accessors on those columns continue to work correctly. Callers that useColumn.stringas a fallback for unknown types will correctly fall through to bytes or other representations.