Skip to content

Commit 1b5cbfd

Browse files
committed
Parse threshold value to avoid type coercion
1 parent 99dabc1 commit 1b5cbfd

File tree

1 file changed

+7
-1
lines changed
  • graphemes-api/src/routes/api/v1/match

1 file changed

+7
-1
lines changed

graphemes-api/src/routes/api/v1/match/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ matchRouter.post("/", async (req, res) => {
2626

2727
const { value1, value2, threshold } = req.body;
2828

29-
const comparison = compareValues(value1, value2, threshold ?? 0.9);
29+
// Check for numeric threshold value and default to 0.9 if one isn't present.
30+
const numericThreshold = parseFloat(threshold);
31+
const comparison = compareValues(
32+
value1,
33+
value2,
34+
!isNaN(numericThreshold) ? numericThreshold : 0.9
35+
);
3036

3137
res.status(200).json({
3238
value1: comparison.comparisonValue1,

0 commit comments

Comments
 (0)