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

Conversation

isalga
Copy link
Contributor

@isalga isalga commented Jan 10, 2022

What was the problem?

This PR resolves #3887

How was it solved?

  • Adding function to remove trailing slash

How was it tested?

Manually

@isalga isalga changed the base branch from development to release/2.2.0 January 10, 2022 10:44
@isalga isalga marked this pull request as ready for review January 10, 2022 14:08
@isalga isalga self-assigned this Jan 10, 2022
Comment on lines 25 to 33
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(/\/$/, '');

@isalga isalga requested a review from reyraa January 11, 2022 12:16
@isalga isalga removed the request for review from eniolam1000752 January 11, 2022 14:44
@isalga isalga force-pushed the 3887-fix-url-trailing-slash branch from 359ef28 to 8d814e3 Compare January 11, 2022 15:03
@isalga isalga merged commit 3cd82c1 into release/2.2.0 Jan 11, 2022
@ManuGowda ManuGowda deleted the 3887-fix-url-trailing-slash branch January 11, 2022 20:11
reyraa pushed a commit that referenced this pull request Jan 24, 2022
* Remove

* Create removeTrailingSlash function

* Use regex and add documentation

* Only setAddress for last input

Co-authored-by: Manu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trailing slash makes URL invalid
3 participants