Skip to content

Commit

Permalink
Add error handling for malformed URI components in extractNameFromCon…
Browse files Browse the repository at this point in the history
…figURL
  • Loading branch information
MatinDehghanian committed Feb 3, 2025
1 parent d46f8ba commit bbb5544
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ export const extractNameFromConfigURL = (url) => {
const namePattern = /#([^#]*)/;
const match = url.match(namePattern);

if (match) return decodeURIComponent(match[1]);
if (match) {
try {
return decodeURIComponent(match[1]);
} catch (error) {
console.error("Malformed URI component:", match[1], error);
return match[1];
}
}

if (url.startsWith("vmess://")) {
const encodedString = url.replace("vmess://", "");
const decodedString = atob(encodedString);

try {
const decodedString = atob(encodedString);
return JSON.parse(decodedString).ps;
} catch (error) {
console.error("Invalid vmess URL format:", error);
Expand Down

0 comments on commit bbb5544

Please sign in to comment.