Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number key in cacher breaks when maxParamsLength is set and keys are specified #1289

Closed
leiyangyou opened this issue Jun 10, 2024 · 0 comments

Comments

@leiyangyou
Copy link

leiyangyou commented Jun 10, 2024

Current Behavior

when cacher has maxParamsLength set, if the action also specifies a keys array say ["id"], and the id is of type number, the cacher crashes upon key generation, as hashkey will pass id to crypto.createHash, the length check fails because

1.length < maxLength always fails

the following patch does the trick for now

diff --git a/node_modules/moleculer/src/cachers/base.js b/node_modules/moleculer/src/cachers/base.js
index 3cee84a..06ece92 100644
--- a/node_modules/moleculer/src/cachers/base.js
+++ b/node_modules/moleculer/src/cachers/base.js
@@ -232,7 +232,7 @@ class Cacher {
 					return (
 						keyPrefix +
 						this._hashedKey(
-							isObject(val) ? this._hashedKey(this._generateKeyFromObject(val)) : val
+							isObject(val) ? this._hashedKey(this._generateKeyFromObject(val)) : String(val)
 						)
 					);
 				}
@@ -248,7 +248,7 @@ class Cacher {
 									(i ? "|" : "") +
 									(isObject(val) || Array.isArray(val)
 										? this._hashedKey(this._generateKeyFromObject(val))
-										: val)
+										: String(val))
 								);
 							}, "")
 						)
@icebob icebob closed this as completed in 426fcda Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant