-
Notifications
You must be signed in to change notification settings - Fork 16
dbeaver/dbeaver#38710 fixed non-turso hostnames+ports #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
| import java.util.regex.Matcher; | ||
|
|
||
| public class LibSqlUtils { | ||
|
|
||
|
|
@@ -66,4 +67,20 @@ public static ResultSet executeQuery(Connection connection, String query) throws | |
| return stat.executeQuery(query); | ||
| } | ||
| } | ||
|
|
||
| public static String validateAndFormatUrl(String url) throws LibSqlException { | ||
Nexus6v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Matcher matcher = LibSqlConstants.CONNECTION_URL_PATTERN.matcher(url); | ||
| if (!matcher.matches()) { | ||
| throw new LibSqlException( | ||
| "Invalid connection URL: " + url + | ||
| ".\nExpected URL formats: " + LibSqlConstants.CONNECTION_URL_EXAMPLES | ||
| ); | ||
| } | ||
|
|
||
| String formattedUrl = url.replaceFirst("jdbc:dbeaver:libsql:", ""); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will replace just the first occurrence of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then please either add a regex anchor or put a |
||
| if (formattedUrl.startsWith("libsql://")) { | ||
| formattedUrl = formattedUrl.replaceFirst("libsql://", "https://"); | ||
| } | ||
| return formattedUrl; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * DBeaver - Universal Database Manager | ||
| * Copyright (C) 2010-2025 DBeaver Corp | ||
| * | ||
| * All Rights Reserved. | ||
| * | ||
| * NOTICE: All information contained herein is, and remains | ||
| * the property of DBeaver Corp and its suppliers, if any. | ||
| * The intellectual and technical concepts contained | ||
| * herein are proprietary to DBeaver Corp and its suppliers | ||
| * and may be covered by U.S. and Foreign Patents, | ||
| * patents in process, and are protected by trade secret or copyright law. | ||
| * Dissemination of this information or reproduction of this material | ||
| * is strictly forbidden unless prior written permission is obtained | ||
| * from DBeaver Corp. | ||
| */ | ||
| package com.dbeaver.jdbc.upd.driver.test; | ||
|
|
||
| import com.dbeaver.jdbc.driver.libsql.LibSqlException; | ||
| import com.dbeaver.jdbc.driver.libsql.LibSqlUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| public class LibSqlUtilsTest { | ||
|
|
||
| @Test | ||
| public void testFormatUrl() throws LibSqlException { | ||
| assertFormatError("localhost"); | ||
| assertFormatError("libsql://9M7NAcHfxSZyIm#*yxLY"); | ||
|
|
||
| assertUrlFormat("jdbc:dbeaver:libsql:http://localhost", "http://localhost"); | ||
| assertUrlFormat("jdbc:dbeaver:libsql:https://localhost", "https://localhost"); | ||
| assertUrlFormat("jdbc:dbeaver:libsql:http://localhost:8080", "http://localhost:8080"); | ||
| assertUrlFormat("jdbc:dbeaver:libsql:libsql://localhost", "https://localhost"); | ||
| assertUrlFormat("libsql://turso.url.my-hostname-1", "https://turso.url.my-hostname-1"); | ||
| assertUrlFormat("libsql://turso.url.my-hostname-1:8080", "https://turso.url.my-hostname-1:8080"); | ||
| } | ||
|
|
||
| private void assertUrlFormat(String input, String expected) throws LibSqlException { | ||
| Assert.assertEquals(expected, LibSqlUtils.validateAndFormatUrl(input)); | ||
| } | ||
|
|
||
| private void assertFormatError(String input) { | ||
| String expectedMessage = "Invalid connection URL: " + input + | ||
| ".\nExpected URL formats: jdbc:dbeaver:libsql:<hostname>, libsql://<hostname>"; | ||
| try { | ||
| LibSqlUtils.validateAndFormatUrl(input); | ||
| Assert.fail("Expected exception: " + expectedMessage); | ||
| } catch (LibSqlException e) { | ||
| Assert.assertEquals( | ||
| expectedMessage, | ||
| e.getMessage() | ||
| ); | ||
| } | ||
Nexus6v2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.