Skip to content

Commit

Permalink
Merge pull request #31 from Ma11hewThomas/main
Browse files Browse the repository at this point in the history
fix(encoders): add error handling to en/decodeURI
  • Loading branch information
drodil authored Mar 24, 2023
2 parents f3c3110 + 4eb84b0 commit 15521fc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/toolbox/src/components/Encoders/UrlEncode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ export const UrlEncode = () => {
const [mode, setMode] = React.useState('Encode');

useEffect(() => {
if (mode === 'Encode') {
setOutput(encodeURI(input));
} else {
setOutput(decodeURI(input));
let url = '';
let errorMessage = '';
try {
url = mode === 'Encode' ? encodeURI(input) : decodeURI(input);
} catch (error) {
errorMessage = `couldn't ${
mode === 'Encode' ? 'encode' : 'decode'
} URL...`;
}
setOutput(url || errorMessage);
}, [input, mode]);

return (
Expand Down

0 comments on commit 15521fc

Please sign in to comment.