Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[URL] Fix url utility throwing exception #59

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/routes/url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ enum Action {
DECODE = "Decode",
}

//the usage of this function expects a protocol in the url, so we need to add the protocol if its not in the text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comments that document a function generally look like

/**
 * ...
*/

function textToUrl(text: string) {
return text.startsWith("https%3A%2F%2F") ? decodeURIComponent(text) : text;
// decode encoded text - we check index of "://" since it could be https or http
if (text.indexOf("%3A%2F%2F") <= 5) {
return decodeURIComponent(text);
// if text starts with http (or https), we return text as is
} else if (text.startsWith("http")) {
return text;
}
// if text does not include protocol, we add it.
return `https://${text}`;
}

async function encode(text: string): Promise<string | JsonURL> {
Expand Down
Loading