Skip to content

Commit 232d200

Browse files
authored
Merge pull request #301 from erizocosmico/fix/language-unknown-langs
internal/function: language should return nil for unknown languages
2 parents fb199fb + c36ef3e commit 232d200

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

internal/function/language.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ func (f *Language) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
110110
blob = right.([]byte)
111111
}
112112

113-
return enry.GetLanguage(path, blob), nil
113+
if lang := enry.GetLanguage(path, blob); lang != "" {
114+
return lang, nil
115+
}
116+
117+
return nil, nil
114118
}
115119

116120
// Children implements the Expression interface.

internal/function/language_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestLanguage(t *testing.T) {
2020
{"right is null", sql.NewRow("foo", nil), nil, nil},
2121
{"both are null", sql.NewRow(nil, nil), nil, nil},
2222
{"only path is given", sql.NewRow("foo.rb"), "Ruby", nil},
23+
{"only path is given", sql.NewRow("foo.foobar"), nil, nil},
2324
{"too many args given", sql.NewRow("foo.rb", "bar", "baz"), nil, sql.ErrInvalidArgumentNumber},
2425
{"path and blob are given", sql.NewRow("foo", "#!/usr/bin/env python\n\nprint 'foo'"), "Python", nil},
2526
{"invalid blob type given", sql.NewRow("foo", 5), nil, sql.ErrInvalidType},

0 commit comments

Comments
 (0)