Closed Justintime50 closed 3 months ago
Hi,
I just noticed that this regex is missing an edge case. When I initially wrote it, I only saw examples of weight
with values of null
and whole numbers formatted with .0
. After running the regex for a while, I discovered that weight
can also have other decimal values, like 614.4
. In this case, the old regex does not ignore these values and incorrectly inserts .0
, resulting in 614.4
being transformed into 61.04.4
. I have now updated the regex to support these cases.
.replace(/("weight":\s*)(\d+)(\s*)(?=,|\})/g,"$1$2.0")
We have been running this updated version and have had 0 webhook validation errors.
Fantastic, thanks for the updated info! We've incorporated that.
Description
When the
weight
field is present on a webhook (eg: tracking update), it gets converted but JS drops the decimal if.0
which often is the case. This breaks webhook validation because HMAC signatures won't match if it's altered at all. This properly puts back the.0
if necessary and missing to ensure that validation will continue to work. Tests validate that we properly compare the signaturesTesting
Pull Request Type
Please select the option(s) that are relevant to this PR.