From b91a6a6969674f43e791d12a1d2d776df370cead Mon Sep 17 00:00:00 2001 From: Rajeev Singh Naruka Date: Wed, 4 Sep 2024 17:39:44 +0530 Subject: [PATCH] fix: merge parseTweet options correctly. The existing implementation overrides the default options with the new ones if provided. In that case, if partial options are provided, this can lead to unexpected errors (Null values in return object) because default values are all reset. --- js/src/parseTweet.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/src/parseTweet.js b/js/src/parseTweet.js index 2dc2e50f6..d3feccbbe 100644 --- a/js/src/parseTweet.js +++ b/js/src/parseTweet.js @@ -28,7 +28,12 @@ import urlHasHttps from './regexp/urlHasHttps'; * displayRangeEnd {int} end index of display text (inclusive) in utf16 */ const parseTweet = function(text = '', options = configs.defaults) { - const mergedOptions = Object.keys(options).length ? options : configs.defaults; + // Merge the provided options with the defaults + const mergedOptions = { + ...configs.defaults, + ...options + }; + const { defaultWeight, emojiParsingEnabled, scale, maxWeightedTweetLength, transformedURLLength } = mergedOptions; const normalizedText = typeof String.prototype.normalize === 'function' ? text.normalize() : text;