Skip to content

Commit

Permalink
fix: bookmarklet malformed uri error
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Apr 18, 2024
1 parent 33c5761 commit d042684
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/webcrack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ export async function webcrack(

const isBookmarklet = /^javascript:./.test(code);
if (isBookmarklet) {
code = decodeURIComponent(code.replace(/^javascript:/, ''));
code = code
.replace(/^javascript:/, '')
.split(/%(?![a-f\d]{2})/i)
.map(decodeURIComponent)
.join('%');
}

let ast: ParseResult<t.File> = null!;
Expand Down
10 changes: 10 additions & 0 deletions packages/webcrack/test/transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ test('decode bookmarklet', async () => {
})();"
`);
});

test('decode malformed bookmarklet', async () => {
const code = `javascript:(function()%7Breturn%20v%F%3B%7D)()`;
const result = await webcrack(code);
expect(result.code).toMatchInlineSnapshot(`
"(function () {
return v % F;
})();"
`);
});

0 comments on commit d042684

Please sign in to comment.