Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: webpack/loader-utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.2
Choose a base ref
...
head repository: webpack/loader-utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.3
Choose a head ref
  • 4 commits
  • 8 files changed
  • 3 contributors

Commits on Nov 4, 2021

  1. Copy the full SHA
    8c2d24e View commit details
  2. Copy the full SHA
    90c7c4b View commit details

Commits on Oct 20, 2022

  1. Copy the full SHA
    a93cf6f View commit details
  2. chore(release): 2.0.3

    alexander-akait committed Oct 20, 2022
    Copy the full SHA
    7162619 View commit details
Showing with 95 additions and 13 deletions.
  1. +14 −0 CHANGELOG.md
  2. +7 −3 lib/getHashDigest.js
  3. +64 −0 lib/hash/BatchedHash.js
  4. +1 −1 lib/hash/wasm-hash.js
  5. +1 −1 lib/parseQuery.js
  6. +1 −1 package.json
  7. +2 −2 test/getHashDigest.test.js
  8. +5 −5 test/interpolateName.test.js
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,20 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [2.0.3](https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.3) (2022-10-20)


### Bug Fixes

* **security:** prototype pollution exploit ([#217](https://github.com/webpack/loader-utils/issues/217)) ([a93cf6f](https://github.com/webpack/loader-utils/commit/a93cf6f4702012030f6b5ee8340d5c95ec1c7d4c))

### [2.0.2](https://github.com/webpack/loader-utils/compare/v2.0.1...v2.0.2) (2021-11-04)


### Bug Fixes

* base64 generation and unicode characters ([#197](https://github.com/webpack/loader-utils/issues/197)) ([8c2d24e](https://github.com/webpack/loader-utils/commit/8c2d24ee400bc4567335e97ee6004c3baa6ef66f))

### [2.0.1](https://github.com/webpack/loader-utils/compare/v2.0.0...v2.0.1) (2021-10-29)


10 changes: 7 additions & 3 deletions lib/getHashDigest.js
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ function encodeBufferToBase(buffer, base) {
}

let createMd4 = undefined;
let BatchedHash = undefined;

function getHashDigest(buffer, hashType, digestType, maxLength) {
hashType = hashType || 'md4';
@@ -53,9 +54,13 @@ function getHashDigest(buffer, hashType, digestType, maxLength) {
if (error.code === 'ERR_OSSL_EVP_UNSUPPORTED' && hashType === 'md4') {
if (createMd4 === undefined) {
createMd4 = require('./hash/md4');

if (BatchedHash === undefined) {
BatchedHash = require('./hash/BatchedHash');
}
}

hash = createMd4();
hash = new BatchedHash(createMd4());
}

if (!hash) {
@@ -72,8 +77,7 @@ function getHashDigest(buffer, hashType, digestType, maxLength) {
digestType === 'base49' ||
digestType === 'base52' ||
digestType === 'base58' ||
digestType === 'base62' ||
digestType === 'base64'
digestType === 'base62'
) {
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(
0,
64 changes: 64 additions & 0 deletions lib/hash/BatchedHash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const MAX_SHORT_STRING = require('./wasm-hash').MAX_SHORT_STRING;

class BatchedHash {
constructor(hash) {
this.string = undefined;
this.encoding = undefined;
this.hash = hash;
}

/**
* Update hash {@link https://nodejs.org/api/crypto.html#crypto_hash_update_data_inputencoding}
* @param {string|Buffer} data data
* @param {string=} inputEncoding data encoding
* @returns {this} updated hash
*/
update(data, inputEncoding) {
if (this.string !== undefined) {
if (
typeof data === 'string' &&
inputEncoding === this.encoding &&
this.string.length + data.length < MAX_SHORT_STRING
) {
this.string += data;

return this;
}

this.hash.update(this.string, this.encoding);
this.string = undefined;
}

if (typeof data === 'string') {
if (
data.length < MAX_SHORT_STRING &&
// base64 encoding is not valid since it may contain padding chars
(!inputEncoding || !inputEncoding.startsWith('ba'))
) {
this.string = data;
this.encoding = inputEncoding;
} else {
this.hash.update(data, inputEncoding);
}
} else {
this.hash.update(data);
}

return this;
}

/**
* Calculates the digest {@link https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding}
* @param {string=} encoding encoding of the return value
* @returns {string|Buffer} digest
*/
digest(encoding) {
if (this.string !== undefined) {
this.hash.update(this.string, this.encoding);
}

return this.hash.digest(encoding);
}
}

module.exports = BatchedHash;
2 changes: 1 addition & 1 deletion lib/hash/wasm-hash.js
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ class WasmHash {
endPos += 2;
} else {
// bail-out for weird chars
endPos += mem.write(data.slice(endPos), endPos, encoding);
endPos += mem.write(data.slice(i), endPos, encoding);
break;
}
}
2 changes: 1 addition & 1 deletion lib/parseQuery.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ function parseQuery(query) {
}

const queryArgs = query.split(/[,&]/g);
const result = {};
const result = Object.create(null);

queryArgs.forEach((arg) => {
const idx = arg.indexOf('=');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "loader-utils",
"version": "2.0.1",
"version": "2.0.3",
"author": "Tobias Koppers @sokra",
"description": "utils for webpack loaders",
"dependencies": {
4 changes: 2 additions & 2 deletions test/getHashDigest.test.js
Original file line number Diff line number Diff line change
@@ -12,15 +12,15 @@ describe('getHashDigest()', () => {
'6f8db599de986fab7a21625b7916589c',
],
['test string', 'md5', 'hex', 4, '6f8d'],
['test string', 'md5', 'base64', undefined, '2sm1pVmS8xuGJLCdWpJoRL'],
['test string', 'md5', 'base64', undefined, 'b421md6Yb6t6IWJbeRZYnA=='],
['test string', 'md5', 'base52', undefined, 'dJnldHSAutqUacjgfBQGLQx'],
['test string', 'md5', 'base26', 6, 'bhtsgu'],
[
'test string',
'sha512',
'base64',
undefined,
'2IS-kbfIPnVflXb9CzgoNESGCkvkb0urMmucPD9z8q6HuYz8RShY1-tzSUpm5-Ivx_u4H1MEzPgAhyhaZ7RKog',
'EObWR69EYkRC84jCwUp4f/ixfmFluD12fsBHdo2MvLcaGjIm58x4Frx5wEJ9lKnaaIxBo5kse/Xk18w+C+XbrA==',
],
[
'test string',
10 changes: 5 additions & 5 deletions test/interpolateName.test.js
Original file line number Diff line number Diff line change
@@ -62,13 +62,13 @@ describe('interpolateName()', () => {
'/app/img/image.png',
'[sha512:hash:base64:7].[ext]',
'test content',
'2BKDTjl.png',
'DL9MrvO.png',
],
[
'/app/img/image.png',
'[sha512:contenthash:base64:7].[ext]',
'test content',
'2BKDTjl.png',
'DL9MrvO.png',
],
[
'/app/dir/file.png',
@@ -116,13 +116,13 @@ describe('interpolateName()', () => {
'/lib/components/modal/modal.css',
'[name].[md5:hash:base64:20].[ext]',
'test content',
'modal.1n8osQznuT8jOAwdzg_n.css',
'modal.lHP90NiApDwht3eNNIch.css',
],
[
'/lib/components/modal/modal.css',
'[name].[md5:contenthash:base64:20].[ext]',
'test content',
'modal.1n8osQznuT8jOAwdzg_n.css',
'modal.lHP90NiApDwht3eNNIch.css',
],
// Should not interpret without `hash` or `contenthash`
[
@@ -265,7 +265,7 @@ describe('interpolateName()', () => {
],
[
[{}, '[hash:base64]', { content: 'test string' }],
'2LIG3oc1uBNmwOoL7kXgoK',
'Lgbt1PFiMmjFpRcw2KCyrw==',
'should interpolate [hash] token with options',
],
[