contentful-database-importer.rb icon indicating copy to clipboard operation
contentful-database-importer.rb copied to clipboard

Truncate ID to 64 chars

Open cachrisman opened this issue 7 years ago • 1 comments

Updated asset_id_from_name to truncate the returned id to 64 characters as Contentful's API doesn't allow more than 64 characters. See https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/resource-ids

cachrisman avatar Jul 24 '17 22:07 cachrisman

Hey @cachrisman,

Thanks for the contribution.

There are 2 things that raise warnings from this and would love to have improved:

  1. This will allow for collisions, E.g. a_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery_long_asset_name_1 and a_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery_long_asset_name_2 would both get truncated to a_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery_long_asset_name leading to a collision which we do not want. Better have it then SHA1 hash it + base62 encode it or something alike on longer IDs so that this issue is avoided.

  2. Please add a test so that we can check that the asset ID is being generated as expected.

Please let me know if you can do this changes.

Cheers

dlitvakb avatar Jul 25 '17 00:07 dlitvakb