diff --git a/.travis.yml b/.travis.yml index 303b76c..183e7bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: + - "8" - "7" - "6" - "5" diff --git a/CHANGELOG.md b/CHANGELOG.md index c0422a2..4b5dbeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.3.4] - 2017-08-08 +### Changed +- Corrected shortenUUID function in [index.js] +- Added test cases for uppercase in [test/index.js] +- Added 2.3.4 fix notes in [README.md] +- Refactored "random" test cases so only the assertions loop in [test/index.js] +- Updated devDependencies for codeclimate-test-reporter in [package.json] +- Included Node 8.x support in [.travis.yml] + ## [2.3.3] - 2017-05-22 ### Changed - Changed [.npmignore] To remove dist, so the built files end up on the package. No code changes. diff --git a/README.md b/README.md index b78111b..708b256 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Generate and translate standard UUIDs into shorter - or just *different* - formats and back. -## v2.3.3 +## v2.3.4 short-uuid provides RFC4122 v4-compliant UUIDs, thanks to [`uuid`](https://github.com/kelektiv/node-uuid). @@ -17,7 +17,12 @@ with compiled browser-ready files in the npm package for convenience. The librar 2.3.0 corrects [Snyk](https://snyk.io) vulnerability protection to a dev dependency. 2.3.1 merges the 2.1.x fixes into version history. 2.3.2 merges a TypeScript definition from [alexturek](https://github.com/alexturek). -2.3.3 fixes missing /dist folder from the npm module. +2.3.3 fixes missing /dist folder from the npm module. +2.3.4 corrects the behavior for UUIDs with uppercase letters. + +**Prior to 2.3.4, passing a UUID with capital letters would cause an incorrect conversion.** +All UUIDs are now converted to lowercase before translation. +UUIDs generated by the `uuid` library were always lowercase. This was a test case miss. ### v2.2.0 Deprecated 2.2.0 incorrectly added Snyk as a production dependency. It has been deprecated. diff --git a/index.js b/index.js index 67ce82f..2a0ea7e 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ module.exports = (function(){ * @returns {string} */ function shortenUUID (longId, translator) { - return translator(longId.replace(/-/g,'')); + return translator(longId.toLowerCase().replace(/-/g,'')); } /** diff --git a/package.json b/package.json index d6f15cb..361ff32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "short-uuid", - "version": "2.3.3", + "version": "2.3.4", "description": "Create and translate standard UUIDs with shorter formats.", "main": "index.js", "typings": "index.d.ts", @@ -32,7 +32,7 @@ "uuid": "^3.0.0" }, "devDependencies": { - "codeclimate-test-reporter": "^0.4.0", + "codeclimate-test-reporter": "^0.5.0", "grunt": "^1.0.1", "grunt-browserify": "^5.0.0", "grunt-contrib-uglify": "^3.0.0", diff --git a/revisions.md b/revisions.md index 68d9c08..00da32c 100644 --- a/revisions.md +++ b/revisions.md @@ -1,5 +1,13 @@ # Revisions +# v2.3.4 + +2.3.4 corrects the behavior for UUIDs with uppercase letters. + +**Prior to 2.3.4, passing a UUID with capital letters would cause an incorrect conversion.** +All UUIDs are now converted to lowercase before translation. +UUIDs generated by the `uuid` library were always lowercase. This was a test case miss. + # v2.3.3 2.3.3 fixes missing /dist folder from the npm module. diff --git a/test/index.js b/test/index.js index e360ce2..b35f5eb 100644 --- a/test/index.js +++ b/test/index.js @@ -54,9 +54,7 @@ describe('short-uuid', function(){ var b90 = short(short.constants.cookieBase90); var b58 = short(short.constants.flickrBase58); - var uu, f58, f90; - - for (var i = 0; i < 10; i++) { + var cycle = function(test) { uu = short.uuid(); it('should generate valid UUIDs', function(){ @@ -66,19 +64,48 @@ describe('short-uuid', function(){ f58 = b58.fromUUID(uu); f90 = b90.fromUUID(uu); - it('should translate back from multiple bases', function(){ + test(); + }; + + var uu, f58, f90, i, action; + + it('should generate valid UUIDs', function(){ + action = function() { + assert.ok(validUUIDRegex.test(uu), 'UUID is valid'); + }; + + for (i = 0; i < 10; i++) { + cycle(action); + } + }); + + it('should translate back from multiple bases', function(){ + + action = function() { assert.equal(b58.toUUID(f58), uu, 'Translated b58 matches original'); assert.ok(validUUIDRegex.test(b58.toUUID(f58)), 'Translated UUID is valid'); assert.equal(b90.toUUID(f90), uu, 'Translated b90 matches original'); assert.ok(validUUIDRegex.test(b90.toUUID(f90)), 'Translated UUID is valid'); - }); + }; - it('should return a standard v4 uuid from instance.uuid()', function(){ + for (i = 0; i < 10; i++) { + cycle(action); + } + + }); + + it('should return a standard v4 uuid from instance.uuid()', function(){ + + action = function() { assert.ok(validUUIDRegex.test(b58.uuid()), '.uuid() is a valid UUID'); - }); - } + }; + + for (i = 0; i < 10; i++) { + cycle(action); + } + }); it('should handle UUIDs that begin with zeros', function(){ var someZeros = '00000000-a70c-4ebd-8f2b-540f7e709092'; @@ -93,6 +120,22 @@ describe('short-uuid', function(){ assert.equal(allZeros, b90.toUUID(b90.fromUUID(allZeros)),'Supports starting zeroes'); }); + it('should handle UUID with uppercase letters', function(){ + var uuidWithUpper = '00000013-0000-1000-8000-0026BB765291', + uuidAllLower = uuidWithUpper.toLowerCase(), + + upperB58 = b58.fromUUID(uuidWithUpper), + lowerB58 = b58.fromUUID(uuidAllLower), + + upperBack = b58.toUUID(upperB58), + lowerBack = b58.toUUID(lowerB58); + + assert.equal(upperB58, lowerB58, 'Translates uppercase letters in UUIDs'); + assert.equal(upperBack, lowerBack, 'Translates back to UUID correctly'); + assert.equal(upperBack, uuidAllLower, 'From uppercase matches original lowercase'); + assert.equal(lowerBack, uuidAllLower, 'From lower matches original lowercase'); + }); + }); describe('new', function(){