From 7a0068cf1711014dd03bbf6bee02240e19c2f7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Fri, 13 Jun 2025 13:53:05 +0200 Subject: [PATCH 1/3] Refine path detection logic in InputTypeDetector to exclude single-line inputs without whitespace. Fix #3. --- .../corese/command/utils/InputTypeDetector.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/inria/corese/command/utils/InputTypeDetector.java b/src/main/java/fr/inria/corese/command/utils/InputTypeDetector.java index 24dcb434f..630200865 100644 --- a/src/main/java/fr/inria/corese/command/utils/InputTypeDetector.java +++ b/src/main/java/fr/inria/corese/command/utils/InputTypeDetector.java @@ -85,12 +85,18 @@ private static boolean isClearlySparql(String input) { return false; } - // Exclude if single-line path-like string (e.g. contains slashes, dots) + /* + * Treat it as a real path only when it is + * 1) single-line **and** + * 2) contains no whitespace (typical for file names) + */ boolean isSingleLine = !input.contains("\n"); - boolean containsPathLikeStuff = input.contains("/") || input.contains("\\") || input.contains("."); + boolean hasWhitespace = input.matches(".*\\s+.*"); + boolean looksLikePath = input.matches(".*[\\\\/].*") // slash or back-slash + || input.matches(".*\\.[\\w]{1,4}$"); // ends with .ext - if (isSingleLine && containsPathLikeStuff) { - return false; + if (isSingleLine && !hasWhitespace && looksLikePath) { + return false; // definitely a path ⇒ not SPARQL } return true; From f87ec4fd2c87f444d4232599fbf106f3b03fa6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Fri, 13 Jun 2025 13:53:44 +0200 Subject: [PATCH 2/3] Add tests for detecting inline SPARQL with URI and file paths with spaces --- .../command/utils/InputTypeDetectorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/fr/inria/corese/command/utils/InputTypeDetectorTest.java b/src/test/java/fr/inria/corese/command/utils/InputTypeDetectorTest.java index c58018668..023492a7d 100644 --- a/src/test/java/fr/inria/corese/command/utils/InputTypeDetectorTest.java +++ b/src/test/java/fr/inria/corese/command/utils/InputTypeDetectorTest.java @@ -107,4 +107,19 @@ void detectNonExistentButValidPath() { String path = "some/futureQueryFile"; assertEquals(InputType.FILE_PATH, InputTypeDetector.detect(path)); } + + @Test + @DisplayName("Detect single-line SPARQL that embeds a URI") + void detectInlineSparqlWithUri() { + String query = "PREFIX ex: SELECT * WHERE { ex:Alice a ex:Person }"; + assertEquals(InputType.SPARQL, InputTypeDetector.detect(query)); + } + + @Test + @DisplayName("Detect file path with spaces") + void detectFilePathWithSpaces() { + String path = "data/my query.rq"; + assertEquals(InputType.FILE_PATH, InputTypeDetector.detect(path)); + } + } From 710671e326cad8c4bb82a2271429dfc22e1c3f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20C=C3=A9r=C3=A8s?= Date: Fri, 13 Jun 2025 13:53:55 +0200 Subject: [PATCH 3/3] Update CHANGELOG for version 4.6.1: Fix detection of one-line inline SPARQL queries with URIs --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 270d0ee34..aa5bda364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Corese Changelog +## Version 4.6.1 – + +### Fixed + +- Fixed bug where one-line inline SPARQL queries containing URIs (e.g. `PREFIX ex: SELECT * WHERE { ex:Alice a ex:Person }`) were incorrectly detected as file paths due to slashes or dots in the query string. + ## Version 4.6.0 – 2025-04-11 ### Added