This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fabed205d GH-3416: Parse version when mixed old/new directives in 
RIOT Turtle
9fabed205d is described below

commit 9fabed205d51466b27c63cba7a195f6f00cf61d8
Author: Andy Seaborne <[email protected]>
AuthorDate: Sun Apr 27 21:06:27 2025 +0100

    GH-3416: Parse version when mixed old/new directives in RIOT Turtle
---
 .../org/apache/jena/riot/lang/LangTurtleBase.java  | 29 +++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git 
a/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTurtleBase.java 
b/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTurtleBase.java
index 2cbde02649..3af05be580 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTurtleBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/lang/LangTurtleBase.java
@@ -131,6 +131,10 @@ public abstract class LangTurtleBase extends LangBase {
         Token t = peekToken();
         String x = t.getImage();
         nextToken();
+        processAtDirective(t, x);
+    }
+
+    private void processAtDirective(Token t, String x) {
         if ( x.equals("base") ) {
             directiveBase();
             if ( isStrictMode() )
@@ -192,18 +196,37 @@ public abstract class LangTurtleBase extends LangBase {
 
     protected final void directiveVersion() {
         Token token = peekToken();
-        // Single quoted string only.
+        String directive = null;
+
+        if ( token.hasType(TokenType.LITERAL_LANG) ) {
+            // The case of
+            //    VERSION "1.2"\n@prefix <uri>
+            // Plain string followed by old style directive tokenized as a 
LITERAL_LANG
+            Token subToken = token.getSubToken1();
+            directive = token.getImage2(); // This is the "language" without 
'@'
+            token = subToken;
+        }
+
+        if ( ! token.isString() )
+            exception(token, "Version must be a string (found '" + token + 
"')");
+
+        // Single quoted string only. '1.2' and "1.2", not '''- or """- 
strings.
         StringType stringType = token.getStringType();
         switch(stringType) {
             case STRING1, STRING2 ->{}
             case LONG_STRING1, LONG_STRING2 ->
-                exception(token, "Triple-quoted strings not allowed for the 
version string");
+                exception(token, "Triple-quoted strings not allowed for the 
version string (found '" + token + "')");
             default ->
-                exception(token, "Expected a single-quoted string for the 
version setting (found '" + token + "')");
+                exception(token, "Expected a quoted string for the version 
setting (found '" + token + "')");
         }
         String versionStr = token.getImage();
         emitVersion(versionStr);
         nextToken();
+
+        // If we broke up the LITERAL_LANG token, now process
+        // the language tag part as a directive.
+        if ( directive != null )
+            processAtDirective(token, directive);
     }
 
     // [8] triples ::= subject predicateObjectList

Reply via email to