From b190078313cf4c26aad921b1b0411d1275d1e470 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Mon, 7 Aug 2017 23:47:50 -0400 Subject: [PATCH 1/7] Add Case Sensitivity Tests Tests to identify and resolve #10 --- test/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/index.js b/test/index.js index e360ce2..3522337 100644 --- a/test/index.js +++ b/test/index.js @@ -93,6 +93,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(){ From 4b699d54ce6c55d94d26bcb1c61b2f2bbfcab235 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Mon, 7 Aug 2017 23:49:29 -0400 Subject: [PATCH 2/7] Add toLowerCase to UUID convertor Make all characters passing into any-base lowercase to resolve alphabet mismatch --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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,'')); } /** From 9a92c1543c0896d30f62dc6625581530ffa8c080 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Tue, 8 Aug 2017 00:01:26 -0400 Subject: [PATCH 3/7] Update version and documentation --- CHANGELOG.md | 6 ++++++ README.md | 9 +++++++-- package.json | 2 +- revisions.md | 8 ++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0422a2..4f240d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 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]. + ## [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/package.json b/package.json index d6f15cb..559efd7 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", 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. From 0e79e6787bbc8d597a96afcb727d316d114b0980 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Tue, 8 Aug 2017 00:14:48 -0400 Subject: [PATCH 4/7] Update dev-dependencies Opportunistic update of dev dependency since we are incrementing the version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 559efd7..361ff32 100644 --- a/package.json +++ b/package.json @@ -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", From 2d262d624ebc5b2799e36a9c1732ef3a78ce5d1a Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Tue, 8 Aug 2017 00:16:24 -0400 Subject: [PATCH 5/7] Refactor Tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move for-loops into tests so the test itself isn’t duplicated, only the assertions. Validated the tests still run and pass. --- test/index.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/test/index.js b/test/index.js index 3522337..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'); - }); + }; + + for (i = 0; i < 10; i++) { + cycle(action); + } + + }); - it('should return a standard v4 uuid from instance.uuid()', function(){ + 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'; From 0c89ba8a015095701dabb43b12ecd54882e2b443 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Tue, 8 Aug 2017 00:17:12 -0400 Subject: [PATCH 6/7] Update Travis for Node 8 Add Node 8 testing, just for thoroughness. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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" From fba9f3693bb5edf82571fc7edd90ee79eb0fd573 Mon Sep 17 00:00:00 2001 From: Samuel Rouse Date: Tue, 8 Aug 2017 02:38:58 -0400 Subject: [PATCH 7/7] Update Changelog Add details about smaller auxiliary changes. --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f240d9..4b5dbeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### 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]. +- 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