Skip to content

Commit

Permalink
Return error if graph label isn't a blank node or IRI
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawan Rawal committed Jul 28, 2016
1 parent b6052a0 commit 54a43ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
25 changes: 24 additions & 1 deletion rdf/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,33 @@ var testNQuads = []struct {
},
hasErr: false,
},
{
input: `_:alice <knows> "stuff"^^<xs:string> _:label . # comment`,
nq: NQuad{
Subject: "_:alice",
Predicate: "knows",
ObjectId: "",
ObjectValue: []byte("stuff@@xs:string"),
Label: "_:label",
},
hasErr: false,
},
{
input: `_:alice <knows> "stuff"^^<xs:string> "label" .`,
hasErr: true,
},
{
input: `_:alice <knows> "stuff"^^<xs:string> _uid_:0x01 .`,
hasErr: true,
},
{
input: `_:alice <knows> "stuff"^^<xs:string> <quad> <pentagon> .`,
hasErr: true,
},
{
input: `_:alice <knows> "stuff"^^<xs:string> quad .`,
hasErr: true,
},
{
input: `_:alice <knows> <bob> . <bob>`, // ignores the <bob> after dot.
nq: NQuad{
Expand All @@ -218,7 +241,7 @@ var testNQuads = []struct {
},
},
{
input: `_:alice <likes> "mov\"enpick" .`, // ignores the <bob> after dot.
input: `_:alice <likes> "mov\"enpick" .`,
nq: NQuad{
Subject: "_:alice",
Predicate: "likes",
Expand Down
12 changes: 11 additions & 1 deletion rdf/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Loop:
return lexLabel

} else {
return l.Errorf("Invalid input: %v at lexText", r)
return l.Errorf("Invalid input: %c at lexText", r)
}

case r == '"':
Expand All @@ -96,6 +96,11 @@ Loop:
l.Emit(itemValidEnd)
}
break Loop

case r == ' ':
continue
default:
l.Errorf("Invalid input: %c at lexText", r)
}
}
if l.Pos > l.Start {
Expand Down Expand Up @@ -288,6 +293,11 @@ func lexLabel(l *lex.Lexer) lex.StateFn {
}
if r == '_' {
l.Depth += 1
r = l.Next()
if r != ':' {
return l.Errorf("Invalid char: %c at lexLabel", r)
}
l.Backup()
return lexBlankNode(l, itemLabel, lexText)
}
return l.Errorf("Invalid char: %v at lexLabel", r)
Expand Down

0 comments on commit 54a43ec

Please sign in to comment.