From 865dc03909bd0018c9d6a26ea65814faec8eb1e5 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 17 Mar 2020 14:29:23 +0300 Subject: [PATCH] refactor: switch to `md4` by default (#168) --- README.md | 12 +++++------ lib/getHashDigest.js | 2 +- test/interpolateName.test.js | 40 ++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 37fb15d..affda6e 100644 --- a/README.md +++ b/README.md @@ -180,14 +180,14 @@ The following tokens are replaced in the `name` parameter: * `[query]` the queryof the resource, i.e. `?foo=bar` * `[emoji]` a random emoji representation of `options.content` * `[emoji:]` same as above, but with a customizable number of emojis -* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash) +* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash) * `[:contenthash::]` optionally one can configure - * other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512` + * other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512` * other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64` * and `length` the length in chars -* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash) +* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash) * `[:hash::]` optionally one can configure - * other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512` + * other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512` * other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64` * and `length` the length in chars * `[N]` the N-th match obtained from matching the current file name against `options.regExp` @@ -229,7 +229,7 @@ loaderUtils.interpolateName(loaderContext, "[emoji:4]", { content: ... }); // loaderContext.resourcePath = "/absolute/path/to/app/img/image.png" loaderUtils.interpolateName(loaderContext, "[sha512:hash:base64:7].[ext]", { content: ... }); // => 2BKDTjl.png -// use sha512 hash instead of md5 and with only 7 chars of base64 +// use sha512 hash instead of md4 and with only 7 chars of base64 // loaderContext.resourcePath = "/absolute/path/to/app/img/myself.png" // loaderContext.query.name = @@ -266,7 +266,7 @@ const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, max ``` * `buffer` the content that should be hashed -* `hashType` one of `sha1`, `md5`, `sha256`, `sha512` or any other node.js supported hash type +* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type * `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64` * `maxLength` the maximum length in chars diff --git a/lib/getHashDigest.js b/lib/getHashDigest.js index bbc4e03..45e340e 100644 --- a/lib/getHashDigest.js +++ b/lib/getHashDigest.js @@ -40,7 +40,7 @@ function encodeBufferToBase(buffer, base) { } function getHashDigest(buffer, hashType, digestType, maxLength) { - hashType = hashType || 'md5'; + hashType = hashType || 'md4'; maxLength = maxLength || 9999; const hash = require('crypto').createHash(hashType); diff --git a/test/interpolateName.test.js b/test/interpolateName.test.js index 9f31464..c56e298 100644 --- a/test/interpolateName.test.js +++ b/test/interpolateName.test.js @@ -26,37 +26,37 @@ describe('interpolateName()', () => { '/app/js/javascript.js', 'js/[hash].script.[ext]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js', + 'js/a69899814931280e2f527219ad6ac754.script.js', ], [ '/app/js/javascript.js', 'js/[contenthash].script.[ext]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js', + 'js/a69899814931280e2f527219ad6ac754.script.js', ], [ '/app/page.html', 'html-[hash:6].html', 'test content', - 'html-9473fd.html', + 'html-a69899.html', ], [ '/app/page.html', 'html-[contenthash:6].html', 'test content', - 'html-9473fd.html', + 'html-a69899.html', ], [ '/app/flash.txt', '[hash]', 'test content', - '9473fdd0d880a43c21b7778d34872157', + 'a69899814931280e2f527219ad6ac754', ], [ '/app/flash.txt', '[contenthash]', 'test content', - '9473fdd0d880a43c21b7778d34872157', + 'a69899814931280e2f527219ad6ac754', ], [ '/app/img/image.png', @@ -74,13 +74,13 @@ describe('interpolateName()', () => { '/app/dir/file.png', '[path][name].[ext]?[hash]', 'test content', - '/app/dir/file.png?9473fdd0d880a43c21b7778d34872157', + '/app/dir/file.png?a69899814931280e2f527219ad6ac754', ], [ '/app/dir/file.png', '[path][name].[ext]?[contenthash]', 'test content', - '/app/dir/file.png?9473fdd0d880a43c21b7778d34872157', + '/app/dir/file.png?a69899814931280e2f527219ad6ac754', ], [ '/vendor/test/images/loading.gif', @@ -135,37 +135,37 @@ describe('interpolateName()', () => { '/app/js/javascript.js?foo=bar', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar', + 'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar', ], [ '/app/js/javascript.js?foo=bar&bar=baz', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar&bar=baz', + 'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar&bar=baz', ], [ '/app/js/javascript.js?foo', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo', + 'js/a69899814931280e2f527219ad6ac754.script.js?foo', ], [ '/app/js/javascript.js?', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js', + 'js/a69899814931280e2f527219ad6ac754.script.js', ], [ '/app/js/javascript.js?a', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?a', + 'js/a69899814931280e2f527219ad6ac754.script.js?a', ], [ '/app/js/javascript.js?foo=bar#hash', 'js/[hash].script.[ext][query]', 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar', + 'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar', ], [ '/app/js/javascript.js?foo=bar#hash', @@ -176,7 +176,7 @@ describe('interpolateName()', () => { return 'js/[hash].script.[ext][query]'; }, 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar', + 'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar', ], [ '/app/js/javascript.js?a', @@ -187,7 +187,7 @@ describe('interpolateName()', () => { return 'js/[hash].script.[ext][query]'; }, 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js?a', + 'js/a69899814931280e2f527219ad6ac754.script.js?a', ], [ '/app/js/javascript.js', @@ -198,7 +198,7 @@ describe('interpolateName()', () => { return 'js/[hash].script.[ext][query]'; }, 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js', + 'js/a69899814931280e2f527219ad6ac754.script.js', ], [ '/app/js/javascript.js?', @@ -209,7 +209,7 @@ describe('interpolateName()', () => { return 'js/[hash].script.[ext][query]'; }, 'test content', - 'js/9473fdd0d880a43c21b7778d34872157.script.js', + 'js/a69899814931280e2f527219ad6ac754.script.js', ], ].forEach((test) => { it('should interpolate ' + test[0] + ' ' + test[1], () => { @@ -260,12 +260,12 @@ describe('interpolateName()', () => { run([ [ [{}, '', { content: 'test string' }], - '6f8db599de986fab7a21625b7916589c.bin', + '2e06edd4f1623268c5a51730d8a0b2af.bin', 'should interpolate default tokens', ], [ [{}, '[hash:base64]', { content: 'test string' }], - '2sm1pVmS8xuGJLCdWpJoRL', + '2LIG3oc1uBNmwOoL7kXgoK', 'should interpolate [hash] token with options', ], [