Merge pull request #3793 from filipochnik/reject-empty-label-names

textparse: reject empty label names
pull/3819/head
Fabian Reinartz 7 years ago committed by GitHub
commit dfdd2cb5f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,6 +30,7 @@ const (
lstateTimestamp lstateTimestamp
lstateLabels lstateLabels
lstateLName lstateLName
lstateLEq
lstateLValue lstateLValue
lstateLValueIn lstateLValueIn
) )
@ -54,7 +55,7 @@ D [0-9]
L [a-zA-Z_] L [a-zA-Z_]
M [a-zA-Z_:] M [a-zA-Z_:]
%x lstateName lstateValue lstateTimestamp lstateLabels lstateLName lstateLValue lstateLValueIn %x lstateName lstateValue lstateTimestamp lstateLabels lstateLName lstateLEq lstateLValue lstateLValueIn
%yyc c %yyc c
@ -84,8 +85,10 @@ M [a-zA-Z_:]
<lstateLabels>(,?[ \t]*) l.state = lstateLName <lstateLabels>(,?[ \t]*) l.state = lstateLName
l.offsets = append(l.offsets, l.i) l.offsets = append(l.offsets, l.i)
<lstateLName>{L}({L}|{D})* l.offsets = append(l.offsets, l.i) <lstateLName>{L}({L}|{D})* l.state = lstateLEq
<lstateLName>[ \t]*= l.state = lstateLValue l.offsets = append(l.offsets, l.i)
<lstateLEq>[ \t]*= l.state = lstateLValue
<lstateLValue>[ \t]+ <lstateLValue>[ \t]+
<lstateLValue>\" l.state = lstateLValueIn <lstateLValue>\" l.state = lstateLValueIn

@ -31,6 +31,7 @@ const (
lstateTimestamp lstateTimestamp
lstateLabels lstateLabels
lstateLName lstateLName
lstateLEq
lstateLValue lstateLValue
lstateLValueIn lstateLValueIn
) )
@ -67,10 +68,12 @@ yystate0:
goto yystart21 goto yystart21
case 5: // start condition: lstateLName case 5: // start condition: lstateLName
goto yystart26 goto yystart26
case 6: // start condition: lstateLValue case 6: // start condition: lstateLEq
goto yystart30 goto yystart28
case 7: // start condition: lstateLValueIn case 7: // start condition: lstateLValue
goto yystart33 goto yystart31
case 8: // start condition: lstateLValueIn
goto yystart34
} }
goto yystate0 // silence unused label error goto yystate0 // silence unused label error
@ -323,103 +326,112 @@ yystart26:
switch { switch {
default: default:
goto yyabort goto yyabort
case c == '=':
goto yystate28
case c == '\t' || c == ' ':
goto yystate27
case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': case c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z':
goto yystate29 goto yystate27
} }
yystate27: yystate27:
c = l.next() c = l.next()
switch { switch {
default: default:
goto yyabort goto yyrule10
case c == '=': case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z':
goto yystate28
case c == '\t' || c == ' ':
goto yystate27 goto yystate27
} }
goto yystate28 // silence unused label error
yystate28: yystate28:
c = l.next() c = l.next()
goto yyrule11 yystart28:
switch {
default:
goto yyabort
case c == '=':
goto yystate30
case c == '\t' || c == ' ':
goto yystate29
}
yystate29: yystate29:
c = l.next() c = l.next()
switch { switch {
default: default:
goto yyrule10 goto yyabort
case c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z': case c == '=':
goto yystate30
case c == '\t' || c == ' ':
goto yystate29 goto yystate29
} }
goto yystate30 // silence unused label error
yystate30: yystate30:
c = l.next() c = l.next()
yystart30: goto yyrule11
goto yystate31 // silence unused label error
yystate31:
c = l.next()
yystart31:
switch { switch {
default: default:
goto yyabort goto yyabort
case c == '"': case c == '"':
goto yystate32 goto yystate33
case c == '\t' || c == ' ': case c == '\t' || c == ' ':
goto yystate31 goto yystate32
} }
yystate31: yystate32:
c = l.next() c = l.next()
switch { switch {
default: default:
goto yyrule12 goto yyrule12
case c == '\t' || c == ' ': case c == '\t' || c == ' ':
goto yystate31 goto yystate32
} }
yystate32: yystate33:
c = l.next() c = l.next()
goto yyrule13 goto yyrule13
goto yystate33 // silence unused label error goto yystate34 // silence unused label error
yystate33: yystate34:
c = l.next() c = l.next()
yystart33: yystart34:
switch { switch {
default: default:
goto yyabort goto yyabort
case c == '"': case c == '"':
goto yystate35
case c == '\\':
goto yystate36 goto yystate36
case c == '\\':
goto yystate37
case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ':
goto yystate34 goto yystate35
} }
yystate34: yystate35:
c = l.next() c = l.next()
switch { switch {
default: default:
goto yyabort goto yyabort
case c == '"': case c == '"':
goto yystate35
case c == '\\':
goto yystate36 goto yystate36
case c == '\\':
goto yystate37
case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ': case c >= '\x01' && c <= '!' || c >= '#' && c <= '[' || c >= ']' && c <= 'ÿ':
goto yystate34 goto yystate35
} }
yystate35: yystate36:
c = l.next() c = l.next()
goto yyrule14 goto yyrule14
yystate36: yystate37:
c = l.next() c = l.next()
switch { switch {
default: default:
goto yyabort goto yyabort
case c >= '\x01' && c <= '\t' || c >= '\v' && c <= 'ÿ': case c >= '\x01' && c <= '\t' || c >= '\v' && c <= 'ÿ':
goto yystate34 goto yystate35
} }
yyrule1: // \0 yyrule1: // \0
@ -471,6 +483,7 @@ yyrule9: // (,?[ \t]*)
} }
yyrule10: // {L}({L}|{D})* yyrule10: // {L}({L}|{D})*
{ {
l.state = lstateLEq
l.offsets = append(l.offsets, l.i) l.offsets = append(l.offsets, l.i)
goto yystate0 goto yystate0
} }

@ -182,6 +182,10 @@ func TestParseErrors(t *testing.T) {
input: "something_weird{problem=\"", input: "something_weird{problem=\"",
err: "no token found", err: "no token found",
}, },
{
input: "empty_label_name{=\"\"} 0",
err: "no token found",
},
} }
for _, c := range cases { for _, c := range cases {

Loading…
Cancel
Save