-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent numeric overflow with hashStr function (#141)
The 'data-react-paypal-script-id' attribute uses the hash value from this `hashStr(JSON.stringify(options))` function. This change fixes an issue where a large `options` object could cause a numeric overflow.
- Loading branch information
1 parent
002059d
commit 9914f60
Showing
2 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { hashStr } from "./utils"; | ||
|
||
describe("hashStr", () => { | ||
test("should match the hash from the argument string", () => { | ||
expect(hashStr("react")).toMatchInlineSnapshot(`"xxhjw"`); | ||
expect(hashStr("react-js.braintree")).toMatchInlineSnapshot( | ||
`"xxhjbzppoallaomelb"` | ||
); | ||
expect(hashStr("react-js.paypal")).toMatchInlineSnapshot( | ||
`"xxhjbzppiqfhtje"` | ||
); | ||
expect(hashStr("")).toMatchInlineSnapshot(`""`); | ||
expect( | ||
hashStr( | ||
JSON.stringify({ | ||
"client-id": | ||
"AfmdXiQAZD1rldTeFe9RNvsz8eBBG-Mltqh6h-iocQ1GUNuXIDnCie9tHcueD_NrMWB9dTlWl34xEK7V", | ||
currency: "USD", | ||
intent: "authorize", | ||
debug: false, | ||
vault: false, | ||
locale: "US", | ||
"data-namespace": "braintree", | ||
}) | ||
) | ||
).toMatchInlineSnapshot( | ||
`"iiuovjsqddgseaaouopvvtcqciewjblfycugmepzoirvygvhquvfthtdttqasyqcdzbzaepjvxhbwsrjhhcurjzroipxqyishjiubldxsiumrlgiscmehhggkwzxusrrdpdxisuuektdeudjrtosskdpcksyhttbqsqsvdsoaugkffisgkusjvhthnqmlzgqccmutvqaztoqu"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters