Skip to content

Commit

Permalink
Allow uppercase package name in package query expressions
Browse files Browse the repository at this point in the history
Fixes: #636

Before this fix, aptly was always treating strings starting with
uppercase letter as field name, which was breaking package queries
like `VMware-Horizon-Client_4.5.0_all`.

Now aptly accepts only fields which don't contain underscore, and
everything else would be parsed as package reference.
  • Loading branch information
smira committed Sep 18, 2017
1 parent 985f1a1 commit 50035d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion query/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (p *parser) D() deb.PackageQuery {
operator, value := p.Condition()

r, _ := utf8.DecodeRuneInString(field)
if strings.HasPrefix(field, "$") || unicode.IsUpper(r) {
if strings.HasPrefix(field, "$") || (unicode.IsUpper(r) && !strings.ContainsRune(field, '_')) {
// special field or regular field
q := &deb.FieldQuery{Field: field, Relation: operatorToRelation(operator), Value: value}
if q.Relation == deb.VersionRegexp {
Expand Down
12 changes: 12 additions & 0 deletions query/syntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func (s *SyntaxSuite) TestParsing(c *C) {
c.Assert(err, IsNil)
c.Check(q, DeepEquals, &deb.PkgQuery{Pkg: "alien-data", Version: "1.3.4~dev", Arch: "i386"})

l, _ = lex("query", "Alien-data_1.3.4~dev_i386")
q, err = parse(l)

c.Assert(err, IsNil)
c.Check(q, DeepEquals, &deb.PkgQuery{Pkg: "Alien-data", Version: "1.3.4~dev", Arch: "i386"})

l, _ = lex("query", "Name")
q, err = parse(l)

c.Assert(err, IsNil)
c.Check(q, DeepEquals, &deb.FieldQuery{Field: "Name"})

l, _ = lex("query", "package (> 5.3.7) {amd64}")
q, err = parse(l)

Expand Down

0 comments on commit 50035d5

Please sign in to comment.