This is an automated email from the ASF dual-hosted git repository.
mihaibudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new e56b063689 [CALCITE-7600] Quote PARSE_URL key before building the
query regex
e56b063689 is described below
commit e56b0636899c29205588c6a8ee0be274cb442fea
Author: alhudz <[email protected]>
AuthorDate: Wed Jun 10 10:36:13 2026 +0530
[CALCITE-7600] Quote PARSE_URL key before building the query regex
---
.../src/main/java/org/apache/calcite/runtime/SqlFunctions.java | 2 +-
.../src/main/java/org/apache/calcite/test/SqlOperatorTest.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 7211f78de3..90ed84c761 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -1859,7 +1859,7 @@ public static String convertOracle(String s, String...
args) {
@Deterministic
public static class ParseUrlFunction {
static Pattern keyToPattern(String keyToExtract) {
- return Pattern.compile("(&|^)" + keyToExtract + "=([^&]*)");
+ return Pattern.compile("(&|^)" + Pattern.quote(keyToExtract) +
"=([^&]*)");
}
private final LoadingCache<String, Pattern> cache =
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index d399890342..080a704a8c 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -5204,6 +5204,16 @@ void testBitGetFunc(SqlOperatorFixture f, String
functionName) {
"VARCHAR");
f.checkNull("parse_url('http://calcite.apache.org/path1/p.php?k1=v1&k2=v2#Ref1',"
+ " 'QUERY', 'k3')");
+ // key is matched literally, regex metacharacters do not match other keys
+
f.checkNull("parse_url('http://calcite.apache.org/path1/p.php?k1=v1&k2=v2#Ref1',"
+ + " 'QUERY', 'k.')");
+
f.checkString("parse_url('http://calcite.apache.org/path1/p.php?a.b=v1&axb=v2#Ref1',"
+ + " 'QUERY', 'a.b')",
+ "v1",
+ "VARCHAR");
+ // a key that is not a valid regex must not raise an error
+
f.checkNull("parse_url('http://calcite.apache.org/path1/p.php?k1=v1&k2=v2#Ref1',"
+ + " 'QUERY', '(')");
f.checkString("parse_url('http://calcite.apache.org/path1/p.php?k1=v1&k2=v2#Ref1',"
+ " 'FILE')",
"/path1/p.php?k1=v1&k2=v2",