Skip to content

Commit

Permalink
Publish v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hampuskraft committed Jun 8, 2024
1 parent 16266e9 commit 63986a9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@hampus/itsdangerous",
"version": "2.0.0",
"version": "2.0.1",
"exports": "./src/index.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itsdangerous.js",
"version": "2.0.0",
"version": "2.0.1",
"description": "Safely pass trusted data to untrusted environments and back.",
"keywords": ["hmac", "itsdangerous", "pallets", "python", "security", "serialization"],
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export class Serializer {
* @returns {Uint8Array} - The stringified object as a Uint8Array.
*/
public stringifyPayload(object: $TsFixMe): Uint8Array {
return new TextEncoder().encode(this.serializer.stringify(object));
const json = this.serializer.stringify(object);
const isText = isTextSerializer(this.serializer);
return isText ? new TextEncoder().encode(json) : wantBuffer(json);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ describe.each([Serializer, URLSafeSerializer, URLSafeTimedSerializer])('serializ
'[42].MKCz_0nXQqv7wKpfHZcRtJRmpT2T5uvs9YQsJEhJimqxc9bCLxG31QzS5uC8OVBI1i6jyOLAFNoKaF5ckO9L5Q',
);
});
});

test('readme', async () => {
const serializer = new URLSafeSerializer({secretKey: 'secret key', salt: 'auth'});
const token = await serializer.stringify({id: 5, name: 'itsdangerous'});
expect(token).toEqual('eyJpZCI6NSwibmFtZSI6Iml0c2Rhbmdlcm91cyJ9.6YP6T0BaO67XP--9UzTrmurXSmg');
const data = await serializer.parse(token);
expect(data.name).toEqual('itsdangerous');
});
test('readme', async () => {
const serializer = new URLSafeSerializer({secretKey: 'secret key', salt: 'auth'});
const token = await serializer.stringify({id: 5, name: 'itsdangerous'});
expect(token).toEqual('eyJpZCI6NSwibmFtZSI6Iml0c2Rhbmdlcm91cyJ9.6YP6T0BaO67XP--9UzTrmurXSmg');
const data = await serializer.parse(token);
expect(data.name).toEqual('itsdangerous');
});

0 comments on commit 63986a9

Please sign in to comment.