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

trim on carriage return at svn.go func detectRemoteFromInfoCommand #102

Open
mazeForGit opened this issue Jul 12, 2020 · 2 comments
Open

Comments

@mazeForGit
Copy link

The func detectRemoteFromInfoCommand(infoOut string) (string, error) returns a remote with a trailing "cariagge return".
If this remote is used the commands issued to svn will always respond with an error.

My solution ..

func detectRemoteFromInfoCommand(infoOut string) (string, error) {
sBytes := []byte(infoOut)
urlIndex := strings.Index(infoOut, "URL: ")
if urlIndex == -1 {
return "", fmt.Errorf("Remote not specified in svn info")
}
urlEndIndex := strings.Index(string(sBytes[urlIndex:]), "\n")
if urlEndIndex == -1 {
urlEndIndex = strings.Index(string(sBytes[urlIndex:]), "\r")
if urlEndIndex == -1 {
return "", fmt.Errorf("Unable to parse remote URL for svn info")
}
}

// bugfix : there is a carriage return at the end we need to remove from the string
// original ..
// return string(sBytes[(urlIndex + 5):(urlIndex + urlEndIndex)]), nil

return string(sBytes[(urlIndex + 5):(urlIndex + urlEndIndex) - 1]), nil

}

@tmalaher-telus
Copy link

The current code works only on Unix (\n only) and MacOS (\r only).
Windows has both \r\n at the end of lines.
While your change fixes the problem on windows, it breaks the module on Unix.

My suggestion would be to add this just before the existing return at line 384 in svn.go:

    if infoOut[urlIndex+urlEndIndex-1:urlIndex+urlEndIndex]=="\r" {
        urlEndIndex--
    }

i.e. "If the last character on a line is a carriage return then omit it".
This should not break Unix (character before \n will not be \r)
This should not break MacOS (character before \r will not be \r)
This should fix windows (character before \n will be \r and new code will omit it)

What worries me is how many other places in the code are parsing output from svn commands and trying to strip off the newline characters.

If there are others then each one will need to be individually fixed in some similar fashion.

In this case it would probably be better to create some sort of RunSvnCommandGetOutputAsLines(cmd string, arg ...string) ([]string,error) and have every instance of exec.Command(...).GetCombinedOutput() use that instead...

@tmalaher-telus
Copy link

Or see 43e105a6f4 which fixes this a different way.

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

No branches or pull requests

2 participants