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

Returned value when a language can't be detected #63

Closed
mcarmonaa opened this issue Jul 11, 2017 · 4 comments
Closed

Returned value when a language can't be detected #63

mcarmonaa opened this issue Jul 11, 2017 · 4 comments

Comments

@mcarmonaa
Copy link
Member

this is the code used in language.go

func GetLanguage(filename string, content []byte) string {
	lang := enry.GetLanguage(filename, content)
	if lang == "" {
		lang = enry.OtherLanguage
	}

	lang = strings.ToLower(lang)
	lang = strings.Replace(lang, " ", "-", -1)
	lang = strings.Replace(lang, "+", "p", -1)
	lang = strings.Replace(lang, "#", "sharp", -1)
	return lang
}

but since enry.OtherLanguage was changed to be the string zero value "", the if statement is reassigning again the same value to lang.

What is the expected value this function should return in case a language couldn't be detected?

@abeaumont
Copy link
Contributor

I think current implementation is correct, except that it probably should directly return enry.OtherLanguage directly in the if. The fact that currently enry.OtherLanguage is "" is something that server developers should not care about.

@mcarmonaa
Copy link
Member Author

mcarmonaa commented Jul 11, 2017

enry.GetLanguage doesn't return "" if it can't detect any language, it returns enry.OtherLanguage, so the code should be something like:

lang := enry.GetLanguage(filename, content)
if lang == enry.OtherLanguage {
        return lang
}

Is it ok? I could make a PR to fix it.

@abeaumont
Copy link
Contributor

Oh, I see. If you could do the PR that would be great.

@mcarmonaa
Copy link
Member Author

#64

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