-
-
Notifications
You must be signed in to change notification settings - Fork 909
fix: able to add repo name with "."(dot) in it issue#1451 #1453
Conversation
@arth2002 thanks for getting this PR started. @0-vortex with that failing test I guess if what we really care about are the ones that start with github.com, we could make that a third case. WDYT? |
We should support all repos, this should fix things not become a breaking change. Changing from |
I checked out this PR locally, and I actually think the utils.js would work well like this: export function isValidRepoUrl(url) {
return fullnameValidator(urlToFullName(url));
}
function urlToFullName(url){
const fullname = url.replace(/^(http|https):\/\//i, "") // take off URL protocol
.replace(/^(www\.)*github\.com\//i, "") // take off github.com variant
.replace(/^\/*/ ,"")// take off leading slash(es) if there
.replace(/ /g, ""); // take out spaces
return fullname;
}
function fullnameValidator(fullname){
// take only first two elements
const [owner, repo] = fullname.split("/");
if(!owner || !repo) return [false, null];
// alphanumerics and hyphens are allowed in owner names
const invalidOwnerRegex = /[^a-z0-9-]+/i;
// alphanumerics, hyphens, underscores, and dots are allowed in repo names
const invalidRepoRegex = /[^a-z0-9-_\.]+/i;
const valid = !invalidOwnerRegex.test(owner) && !invalidRepoRegex.test(repo);
// if invalid, return [false, null]
// if valid, return [true, fullname]
return [valid, valid ? fullname : null];
} @arth2002 I think the code above needs some more tweaking but I wanted to bounce the idea off of you and @0-vortex. The test file actually has some issues as well so I'll follow up with a later comment. |
Hard no on this - you have taken a function that checks whether a subset of the URL RFC is relative or not and turned it into a URL validator, that's potentially the opposite of what we are trying to do here; the regexp approach sounds good in theory but if you take a look at RFC 1738 you will understand why this approach is so bad. You can spend weeks perfecting regular expressions like this. To make a better example, I mentioned in the previous review that the third
However, that is going full-on into scope creep. The existing code is meant to catch 3 things at the beginning of the string:
Add the |
Fair enough. @arth2002 is the instruction clear from what @0-vortex was saying? |
Hey @mtfoley sorry to bother you sir
with this one
am I correct? if not can please correct me |
In case you missed the π emoji, it's good! :D |
Please review it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arth2002, I think it would also be helpful to add a couple of tests. The two cases I'd suggest would both be "valid", and would be:
- the repo of the original issue posting ("brob/plug11ty.com")
- the repo "httpie/httpie", just to verify that use case works also.
src/lib/util.js
Outdated
@@ -1,8 +1,8 @@ | |||
export function isValidRepoUrl(url) { | |||
url = url.trim(); | |||
url = url.toLowerCase().trim(); | |||
url = url.substr(0, 1) === "/" ? url.substr(1) : url; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arth2002 I just want you to know you're being very patient with me! That said, I'd suggest we take a moment to change url.substr()
to be url.substring()
. It looks like substr()
is deprecated (though widely supported). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr#browser_compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done π
Looks good to me! |
π This PR is included in version 0.52.1 π The release is available on: Your semantic-release bot π¦π |
What type of PR is this? (check all applicable)
Description
This PR fix #1451
Related Tickets & Documents
Mobile & Desktop Screensh
ots/Recordings
Added tests?
Added to documentation?
[optional] Are there any post-deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?