Skip to content

Commit 865dc03

Browse files
refactor: switch to md4 by default (#168)
1 parent b595cfb commit 865dc03

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ The following tokens are replaced in the `name` parameter:
180180
* `[query]` the queryof the resource, i.e. `?foo=bar`
181181
* `[emoji]` a random emoji representation of `options.content`
182182
* `[emoji:<length>]` same as above, but with a customizable number of emojis
183-
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash)
183+
* `[contenthash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
184184
* `[<hashType>:contenthash:<digestType>:<length>]` optionally one can configure
185-
* other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`
185+
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
186186
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
187187
* and `length` the length in chars
188-
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash)
188+
* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md4 hash)
189189
* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure
190-
* other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`
190+
* other `hashType`s, i. e. `sha1`, `md4`, `md5`, `sha256`, `sha512`
191191
* other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
192192
* and `length` the length in chars
193193
* `[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: ... });
229229
// loaderContext.resourcePath = "/absolute/path/to/app/img/image.png"
230230
loaderUtils.interpolateName(loaderContext, "[sha512:hash:base64:7].[ext]", { content: ... });
231231
// => 2BKDTjl.png
232-
// use sha512 hash instead of md5 and with only 7 chars of base64
232+
// use sha512 hash instead of md4 and with only 7 chars of base64
233233

234234
// loaderContext.resourcePath = "/absolute/path/to/app/img/myself.png"
235235
// loaderContext.query.name =
@@ -266,7 +266,7 @@ const digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, max
266266
```
267267

268268
* `buffer` the content that should be hashed
269-
* `hashType` one of `sha1`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
269+
* `hashType` one of `sha1`, `md4`, `md5`, `sha256`, `sha512` or any other node.js supported hash type
270270
* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`
271271
* `maxLength` the maximum length in chars
272272

lib/getHashDigest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function encodeBufferToBase(buffer, base) {
4040
}
4141

4242
function getHashDigest(buffer, hashType, digestType, maxLength) {
43-
hashType = hashType || 'md5';
43+
hashType = hashType || 'md4';
4444
maxLength = maxLength || 9999;
4545

4646
const hash = require('crypto').createHash(hashType);

test/interpolateName.test.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,37 @@ describe('interpolateName()', () => {
2626
'/app/js/javascript.js',
2727
'js/[hash].script.[ext]',
2828
'test content',
29-
'js/9473fdd0d880a43c21b7778d34872157.script.js',
29+
'js/a69899814931280e2f527219ad6ac754.script.js',
3030
],
3131
[
3232
'/app/js/javascript.js',
3333
'js/[contenthash].script.[ext]',
3434
'test content',
35-
'js/9473fdd0d880a43c21b7778d34872157.script.js',
35+
'js/a69899814931280e2f527219ad6ac754.script.js',
3636
],
3737
[
3838
'/app/page.html',
3939
'html-[hash:6].html',
4040
'test content',
41-
'html-9473fd.html',
41+
'html-a69899.html',
4242
],
4343
[
4444
'/app/page.html',
4545
'html-[contenthash:6].html',
4646
'test content',
47-
'html-9473fd.html',
47+
'html-a69899.html',
4848
],
4949
[
5050
'/app/flash.txt',
5151
'[hash]',
5252
'test content',
53-
'9473fdd0d880a43c21b7778d34872157',
53+
'a69899814931280e2f527219ad6ac754',
5454
],
5555
[
5656
'/app/flash.txt',
5757
'[contenthash]',
5858
'test content',
59-
'9473fdd0d880a43c21b7778d34872157',
59+
'a69899814931280e2f527219ad6ac754',
6060
],
6161
[
6262
'/app/img/image.png',
@@ -74,13 +74,13 @@ describe('interpolateName()', () => {
7474
'/app/dir/file.png',
7575
'[path][name].[ext]?[hash]',
7676
'test content',
77-
'/app/dir/file.png?9473fdd0d880a43c21b7778d34872157',
77+
'/app/dir/file.png?a69899814931280e2f527219ad6ac754',
7878
],
7979
[
8080
'/app/dir/file.png',
8181
'[path][name].[ext]?[contenthash]',
8282
'test content',
83-
'/app/dir/file.png?9473fdd0d880a43c21b7778d34872157',
83+
'/app/dir/file.png?a69899814931280e2f527219ad6ac754',
8484
],
8585
[
8686
'/vendor/test/images/loading.gif',
@@ -135,37 +135,37 @@ describe('interpolateName()', () => {
135135
'/app/js/javascript.js?foo=bar',
136136
'js/[hash].script.[ext][query]',
137137
'test content',
138-
'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar',
138+
'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar',
139139
],
140140
[
141141
'/app/js/javascript.js?foo=bar&bar=baz',
142142
'js/[hash].script.[ext][query]',
143143
'test content',
144-
'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar&bar=baz',
144+
'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar&bar=baz',
145145
],
146146
[
147147
'/app/js/javascript.js?foo',
148148
'js/[hash].script.[ext][query]',
149149
'test content',
150-
'js/9473fdd0d880a43c21b7778d34872157.script.js?foo',
150+
'js/a69899814931280e2f527219ad6ac754.script.js?foo',
151151
],
152152
[
153153
'/app/js/javascript.js?',
154154
'js/[hash].script.[ext][query]',
155155
'test content',
156-
'js/9473fdd0d880a43c21b7778d34872157.script.js',
156+
'js/a69899814931280e2f527219ad6ac754.script.js',
157157
],
158158
[
159159
'/app/js/javascript.js?a',
160160
'js/[hash].script.[ext][query]',
161161
'test content',
162-
'js/9473fdd0d880a43c21b7778d34872157.script.js?a',
162+
'js/a69899814931280e2f527219ad6ac754.script.js?a',
163163
],
164164
[
165165
'/app/js/javascript.js?foo=bar#hash',
166166
'js/[hash].script.[ext][query]',
167167
'test content',
168-
'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar',
168+
'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar',
169169
],
170170
[
171171
'/app/js/javascript.js?foo=bar#hash',
@@ -176,7 +176,7 @@ describe('interpolateName()', () => {
176176
return 'js/[hash].script.[ext][query]';
177177
},
178178
'test content',
179-
'js/9473fdd0d880a43c21b7778d34872157.script.js?foo=bar',
179+
'js/a69899814931280e2f527219ad6ac754.script.js?foo=bar',
180180
],
181181
[
182182
'/app/js/javascript.js?a',
@@ -187,7 +187,7 @@ describe('interpolateName()', () => {
187187
return 'js/[hash].script.[ext][query]';
188188
},
189189
'test content',
190-
'js/9473fdd0d880a43c21b7778d34872157.script.js?a',
190+
'js/a69899814931280e2f527219ad6ac754.script.js?a',
191191
],
192192
[
193193
'/app/js/javascript.js',
@@ -198,7 +198,7 @@ describe('interpolateName()', () => {
198198
return 'js/[hash].script.[ext][query]';
199199
},
200200
'test content',
201-
'js/9473fdd0d880a43c21b7778d34872157.script.js',
201+
'js/a69899814931280e2f527219ad6ac754.script.js',
202202
],
203203
[
204204
'/app/js/javascript.js?',
@@ -209,7 +209,7 @@ describe('interpolateName()', () => {
209209
return 'js/[hash].script.[ext][query]';
210210
},
211211
'test content',
212-
'js/9473fdd0d880a43c21b7778d34872157.script.js',
212+
'js/a69899814931280e2f527219ad6ac754.script.js',
213213
],
214214
].forEach((test) => {
215215
it('should interpolate ' + test[0] + ' ' + test[1], () => {
@@ -260,12 +260,12 @@ describe('interpolateName()', () => {
260260
run([
261261
[
262262
[{}, '', { content: 'test string' }],
263-
'6f8db599de986fab7a21625b7916589c.bin',
263+
'2e06edd4f1623268c5a51730d8a0b2af.bin',
264264
'should interpolate default tokens',
265265
],
266266
[
267267
[{}, '[hash:base64]', { content: 'test string' }],
268-
'2sm1pVmS8xuGJLCdWpJoRL',
268+
'2LIG3oc1uBNmwOoL7kXgoK',
269269
'should interpolate [hash] token with options',
270270
],
271271
[

0 commit comments

Comments
 (0)