From cb231f47672d777998507e09e7f5f303f4dddf0b Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Sun, 17 Mar 2019 15:18:32 +0100
Subject: Fix bug parsing TriG graphs with several squashed trailing dots

---
 NEWS                                    | 3 ++-
 src/n3.c                                | 4 ++--
 tests/good/manifest.ttl                 | 7 +++++++
 tests/good/test-several-eaten-dots.nq   | 3 +++
 tests/good/test-several-eaten-dots.trig | 6 ++++++
 5 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 tests/good/test-several-eaten-dots.nq
 create mode 100644 tests/good/test-several-eaten-dots.trig

diff --git a/NEWS b/NEWS
index a630680e..7502dc89 100644
--- a/NEWS
+++ b/NEWS
@@ -4,8 +4,9 @@ serd (0.30.1) unstable;
   * Fix resolving some URIs against base URIs with no trailing slash
   * Fix colliding blank nodes when parsing TriG
   * Fix missing parse error messages
+  * Fix parsing TriG graphs with several squashed trailing dots
 
- -- David Robillard <d@drobilla.net>  Sun, 11 Nov 2018 11:42:57 +0100
+ -- David Robillard <d@drobilla.net>  Sun, 17 Mar 2019 15:16:31 +0100
 
 serd (0.30.0) stable;
 
diff --git a/src/n3.c b/src/n3.c
index 8832f746..5bd3052c 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1314,11 +1314,11 @@ read_directive(SerdReader* reader)
 static bool
 read_wrappedGraph(SerdReader* reader, ReadContext* ctx)
 {
-	bool ate_dot = false;
-	char s_type  = 0;
 	TRY_RET(eat_byte_check(reader, '{'));
 	read_ws_star(reader);
 	while (peek_byte(reader) != '}') {
+		bool ate_dot = false;
+		char s_type  = 0;
 		ctx->subject = 0;
 		Ref subj = read_subject(reader, *ctx, &ctx->subject, &s_type);
 		if (!subj && ctx->subject) {
diff --git a/tests/good/manifest.ttl b/tests/good/manifest.ttl
index f8641326..25afdd5f 100644
--- a/tests/good/manifest.ttl
+++ b/tests/good/manifest.ttl
@@ -40,6 +40,7 @@
 		<#test-list-subject>
 		<#test-list>
 		<#test-long-string>
+		<#test-several-eaten-dots>
 		<#test-no-spaces>
 		<#test-non-curie-uri>
 		<#test-num>
@@ -239,6 +240,12 @@
 	mf:action <test-long-string.ttl> ;
 	mf:result <test-long-string.nt> .
 
+<#test-several-eaten-dots>
+	rdf:type rdft:TestTrigEval ;
+	mf:name "test-several-eaten-dots" ;
+	mf:action <test-several-eaten-dots.trig> ;
+	mf:result <test-several-eaten-dots.nq> .
+
 <#test-no-spaces>
 	rdf:type rdft:TestTurtleEval ;
 	mf:name "test-no-spaces" ;
diff --git a/tests/good/test-several-eaten-dots.nq b/tests/good/test-several-eaten-dots.nq
new file mode 100644
index 00000000..5cafa59f
--- /dev/null
+++ b/tests/good/test-several-eaten-dots.nq
@@ -0,0 +1,3 @@
+<https://example.com/s> <https://example.com/p1> <https://example.com/o1> <https://example.com/g> .
+<https://example.com/s> <https://example.com/p1> <https://example.com/o2> <https://example.com/g> .
+<https://example.com/s> <https://example.com/p2> <https://example.com/o3> <https://example.com/g> .
diff --git a/tests/good/test-several-eaten-dots.trig b/tests/good/test-several-eaten-dots.trig
new file mode 100644
index 00000000..bab135ed
--- /dev/null
+++ b/tests/good/test-several-eaten-dots.trig
@@ -0,0 +1,6 @@
+prefix : <https://example.com/>
+
+:g {
+  :s :p1 :o1.
+  :s :p1 :o2; :p2 :o3.
+}
\ No newline at end of file
-- 
cgit v1.2.1