aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2022-02-24 14:45:45 +0100
committerGitHub <noreply@github.com>2022-02-24 14:45:45 +0100
commitc785af3f4559ebac52c42f12d17cb118aac383ad (patch)
tree8f0d889133ea726c663be670c293659f786fb531 /internal
parent935af59cf64fbe49eb8baba9fe80e6b236daf593 (diff)
parentb333364cf3e8cfb13c9803d718f56291d7520fbb (diff)
downloadgo-git-c785af3f4559ebac52c42f12d17cb118aac383ad.tar.gz
Merge pull request #475 from michenriksen/revision-fix-endless-loop
revision: fix endless looping in revision parser
Diffstat (limited to 'internal')
-rw-r--r--internal/revision/parser.go4
-rw-r--r--internal/revision/parser_test.go7
2 files changed, 9 insertions, 2 deletions
diff --git a/internal/revision/parser.go b/internal/revision/parser.go
index 8facf17..8a2a719 100644
--- a/internal/revision/parser.go
+++ b/internal/revision/parser.go
@@ -322,6 +322,8 @@ func (p *Parser) parseAt() (Revisioner, error) {
}
return AtDate{t}, nil
+ case tok == eof:
+ return nil, &ErrInvalidRevision{s: `missing "}" in @{<data>} structure`}
default:
date += lit
}
@@ -424,6 +426,8 @@ func (p *Parser) parseCaretBraces() (Revisioner, error) {
p.unscan()
case tok != slash && start:
return nil, &ErrInvalidRevision{fmt.Sprintf(`"%s" is not a valid revision suffix brace component`, lit)}
+ case tok == eof:
+ return nil, &ErrInvalidRevision{s: `missing "}" in ^{<data>} structure`}
case tok != cbrace:
p.unscan()
re += lit
diff --git a/internal/revision/parser_test.go b/internal/revision/parser_test.go
index 98403cc..3a77b2f 100644
--- a/internal/revision/parser_test.go
+++ b/internal/revision/parser_test.go
@@ -183,7 +183,7 @@ func (s *ParserSuite) TestParseWithValidExpression(c *C) {
}
}
-func (s *ParserSuite) TestParseWithUnValidExpression(c *C) {
+func (s *ParserSuite) TestParseWithInvalidExpression(c *C) {
datas := map[string]error{
"..": &ErrInvalidRevision{`must not start with "."`},
"master^1master": &ErrInvalidRevision{`reference must be defined once at the beginning`},
@@ -198,6 +198,9 @@ func (s *ParserSuite) TestParseWithUnValidExpression(c *C) {
"~1": &ErrInvalidRevision{`"~" or "^" statement must have a reference defined at the beginning`},
"master:/test": &ErrInvalidRevision{`":" statement is not valid, could be : :/<regexp>`},
"master:0:README": &ErrInvalidRevision{`":" statement is not valid, could be : :<n>:<path>`},
+ "^{/": &ErrInvalidRevision{`missing "}" in ^{<data>} structure`},
+ "~@{": &ErrInvalidRevision{`missing "}" in @{<data>} structure`},
+ "@@{{0": &ErrInvalidRevision{`missing "}" in @{<data>} structure`},
}
for s, e := range datas {
@@ -230,7 +233,7 @@ func (s *ParserSuite) TestParseAtWithValidExpression(c *C) {
}
}
-func (s *ParserSuite) TestParseAtWithUnValidExpression(c *C) {
+func (s *ParserSuite) TestParseAtWithInvalidExpression(c *C) {
datas := map[string]error{
"{test}": &ErrInvalidRevision{`wrong date "test" must fit ISO-8601 format : 2006-01-02T15:04:05Z`},
"{-1": &ErrInvalidRevision{`missing "}" in @{-n} structure`},