mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Check that status messages start with one of @#$
This commit is contained in:
1 parent
7e6c43e521
commit
9a5a3f636d
1 file changed
+12
@@ -32,6 +32,14 @@ func isDoubleUnderscore(s string) bool {
|
||||
return len(s) >= 2 && s[0] == '_' && s[1] == '_'
|
||||
}
|
||||
|
||||
func isStatusMessage(s string) bool {
|
||||
if s == "" {
|
||||
return false
|
||||
}
|
||||
c := s[0]
|
||||
return (c == '@') || (c == '#') || (c == '$')
|
||||
}
|
||||
|
||||
func Parse(tm *t.Map, filename string, src []t.Token, opts *Options) (*a.File, error) {
|
||||
p := &parser{
|
||||
tm: tm,
|
||||
@@ -220,6 +228,10 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
got := p.tm.ByID(message)
|
||||
return nil, fmt.Errorf(`parse: expected string literal, got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
if s, _ := t.Unescape(p.tm.ByID(message)); !isStatusMessage(s) {
|
||||
return nil, fmt.Errorf(`parse: status message %q does not start with `+
|
||||
`@, # or $ at %s:%d`, s, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if x := p.peek1(); x != t.IDSemicolon {
|
||||
got := p.tm.ByID(x)
|
||||
|
||||
Reference in new issue
Block a user