onflow / nft-catalog

https://www.flow-nft-catalog.com/
The Unlicense
35 stars 11 forks source link

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

Open nvdtf opened 1 year ago

nvdtf commented 1 year ago

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))!
bshahid331 commented 1 year ago

I like this! Something we can implement