Skip to content

Commit

Permalink
Merge pull request #11 from oculus42/fix-uuid-case-sensitivity
Browse files Browse the repository at this point in the history
Fix uuid case sensitivity
  • Loading branch information
oculus42 authored Aug 8, 2017
2 parents ab581b0 + fba9f36 commit f0f4b7a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "8"
- "7"
- "6"
- "5"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (function(){
* @returns {string}
*/
function shortenUUID (longId, translator) {
return translator(longId.replace(/-/g,''));
return translator(longId.toLowerCase().replace(/-/g,''));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions revisions.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
59 changes: 51 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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';
Expand All @@ -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(){
Expand Down

0 comments on commit f0f4b7a

Please sign in to comment.