Skip to content

Invalid character in catalog's dictionary key leads to broken scripts #107

Description

@nvdtf

Most catalog scripts rely on temporary linking to return data (like this):

let tempPathStr = "catalog".concat(key)
let tempPublicPath = PublicPath(identifier: tempPathStr)!
account.link<&{MetadataViews.ResolverCollection}>(
            tempPublicPath,
            target: value.collectionData.storagePath
        )

This leads to errors if the key contains characters like '. This is now true on mainnet catalog.

As a workaround we can hash the key instead, but the downside is more computation:

pub fun cleanStringForPath(_ input: String): String {
  return "catalog".concat(String.encodeHex(HashAlgorithm.SHA3_256.hash(input.utf8)))
}


let tempPublicPath = PublicPath(identifier: cleanStringForPath(key))!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions