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

Fix invalid URL - Closes #3887 #4052

Merged
merged 5 commits into from
Jan 11, 2022
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const validateNode = async (address) => {
}
};

const removeTrailingSlash = (input) => {
const bypassStrings = ['http:/', 'http://', 'https:/', 'https://'];

if (input.charAt(input.length - 1) !== '/' || bypassStrings.includes(input)) {
return input;
}

return input.substring(0, input.length - 1);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use a regex?

Suggested change
const removeTrailingSlash = (input) => {
const bypassStrings = ['http:/', 'http://', 'https:/', 'https://'];
if (input.charAt(input.length - 1) !== '/' || bypassStrings.includes(input)) {
return input;
}
return input.substring(0, input.length - 1);
};
/**
* Removes the trailing slash
*
* @param {string} url - A URL that might end in a slash
* @returns {string} A URL without a trailing slash
*/
const removeTrailingSlash = url => url.replace(/\/$/, '');


const EditMode = ({
t, setMode, dropdownRef,
storedCustomNetwork, networkSelected, customNetworkStored,
Expand All @@ -34,10 +44,11 @@ const EditMode = ({
});
const timeout = useRef();

const validate = (value) => {
const validate = (input) => {
clearTimeout(timeout.current);
// validate the URL with debouncer
timeout.current = setTimeout(() => {
const value = removeTrailingSlash(input);
const normalized = addHttp(value);
setLoading(true);
validateNode(normalized)
Expand Down