From 54a43ecd5fbb06ad0fb5d5b839505afefcdf1092 Mon Sep 17 00:00:00 2001 From: Pawan Rawal Date: Thu, 28 Jul 2016 13:06:20 +0530 Subject: [PATCH] Return error if graph label isn't a blank node or IRI --- rdf/parse_test.go | 25 ++++++++++++++++++++++++- rdf/state.go | 12 +++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/rdf/parse_test.go b/rdf/parse_test.go index 2c69775c995..3b082aecbc0 100644 --- a/rdf/parse_test.go +++ b/rdf/parse_test.go @@ -205,10 +205,33 @@ var testNQuads = []struct { }, hasErr: false, }, + { + input: `_:alice "stuff"^^ _:label . # comment`, + nq: NQuad{ + Subject: "_:alice", + Predicate: "knows", + ObjectId: "", + ObjectValue: []byte("stuff@@xs:string"), + Label: "_:label", + }, + hasErr: false, + }, { input: `_:alice "stuff"^^ "label" .`, hasErr: true, }, + { + input: `_:alice "stuff"^^ _uid_:0x01 .`, + hasErr: true, + }, + { + input: `_:alice "stuff"^^ .`, + hasErr: true, + }, + { + input: `_:alice "stuff"^^ quad .`, + hasErr: true, + }, { input: `_:alice . `, // ignores the after dot. nq: NQuad{ @@ -218,7 +241,7 @@ var testNQuads = []struct { }, }, { - input: `_:alice "mov\"enpick" .`, // ignores the after dot. + input: `_:alice "mov\"enpick" .`, nq: NQuad{ Subject: "_:alice", Predicate: "likes", diff --git a/rdf/state.go b/rdf/state.go index 44e58557a44..9f083f45e54 100644 --- a/rdf/state.go +++ b/rdf/state.go @@ -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 == '"': @@ -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 { @@ -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)