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

Update GIT_RE regex to match on SSH urls with spaces in Project/Repo Names #75

Merged
merged 3 commits into from
Jan 2, 2024

Conversation

monil-patel
Copy link
Contributor

@monil-patel monil-patel commented Nov 21, 2023

fixes #IonicaBizau/git-url-parse#162

Edit - I made a silly mistake. I didn't realize #72 was already opened when I ran off and did this. I am handling one extra thing non encoded whitespace in this change. Open to suggestions on how to handle

I am trying to use git-parse-url and noticing it is failing for Azure DevOps (visual studio) ssh urls where there is a space in the project/repo names.

I traced the bug back to this part of the logic

  const parsed = parsePath(url)

// Potential git-ssh urls
    if (parsed.parse_failed) {

       // Here the ADO SSH Urls with spaces were not matching the GIT_RE, causing it to throw
        const matched = parsed.href.match(GIT_RE) 

        if (matched) {
            parsed.protocols = ["ssh"]
            parsed.protocol = "ssh"
            parsed.resource = matched[2]
            parsed.host = matched[2]
            parsed.user = matched[1]
            parsed.pathname = `/${matched[3]}`
            parsed.parse_failed = false
        } else {
            throwErr("URL parsing failed.")
        }
    }

In this PR I updated the REGEX to allow match on whitespace characters + encoding characters within the path section
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;

The part that changed was the path capture group:
(([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)

  • \s was added to the character list to support white spaces
  • |%[0-9A-Fa-f]{2} to support encodings

Changes

  • Added unit tests to verify it works and doesn't break anything else
  • The build was also breaking for me and I noticed the same was true in github actions, I modified package json which seems to fix it, but pkgroll is a new lib for me so a second pair of eyes on that would be a good thing

@monil-patel monil-patel changed the title Monilpatel/ado ssh fix Update GIT_RE regex to match on ADO urls with spaces in Project/Repo Names Nov 22, 2023
@monil-patel monil-patel changed the title Update GIT_RE regex to match on ADO urls with spaces in Project/Repo Names Update GIT_RE regex to match on SSH urls with spaces in Project/Repo Names Nov 22, 2023
@IonicaBizau IonicaBizau merged commit 26b4719 into IonicaBizau:master Jan 2, 2024
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.

None yet

2 participants