Skip to content

Commit

Permalink
JSON.stringify URLs and check URL validity
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Nov 7, 2023
1 parent 46369fe commit f88c32e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion shared/studio/tabs/auth/state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,25 @@ export class AuthAdminState extends Model({
return "Too many URLs, maximum supported number of URLs is 128."
}

const invalidUrls = urlList.filter((u) => {
try {
new URL(u);
return false;
} catch (e) {
return true;
}
});

if (invalidUrls.length > 0) {
return `List contained the following invalid URLs: ${invalidUrls}`;
}

return null;
},
(urls) => {
if (urls === null) return "{}";
const urlList = urls.split("\n").filter((str) => str.trim() !== "");
return `{${urlList.map((u) => `'${u}'`).join(", ")}}`;
return `{${urlList.map((u) => JSON.stringify(u)).join(", ")}}`;
}
),

Expand Down

0 comments on commit f88c32e

Please sign in to comment.