Skip to content

Commit

Permalink
refactor: switch to md4 by default (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Mar 17, 2020
1 parent b595cfb commit 865dc03
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<length>]` 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)
* `[<hashType>:contenthash:<digestType>:<length>]` 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)
* `[<hashType>:hash:<digestType>:<length>]` 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`
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/getHashDigest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 20 additions & 20 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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?',
Expand All @@ -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], () => {
Expand Down Expand Up @@ -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',
],
[
Expand Down

0 comments on commit 865dc03

Please sign in to comment.