Coder Social home page Coder Social logo

Comments (8)

CaselIT avatar CaselIT commented on May 26, 2024

Hi,

I think this is expected behaviour. A string is interpreted as an url, so the ? delimits the query from the path.

from sqlalchemy.

zzzeek avatar zzzeek commented on May 26, 2024

it looks like a bug . they are creating the URL programattically. The name of the database is a?b=c. that should round trip.

That said, nobody would ever have a database name like that. so what's the XY problem here? (e.g. what do you actually need to do ?)

from sqlalchemy.

AlexeyDmitriev avatar AlexeyDmitriev commented on May 26, 2024

@CaselIT Hi, I might have been confusing:
I understand that if I pass sqlite:///a?b=c then, b=c are parsed as query and it is expected

What in my view is not expected is the fact, that first_url_as_string contains this ? directly (instead of some kind of escaping, e.g urlencoded, etc), so that it would roundtrip well

from sqlalchemy.

zzzeek avatar zzzeek commented on May 26, 2024

this is the patch, this is for 2.1 only as URL adjustments are extremely high risk

diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py
index 1eeb73a23..7565252c7 100644
--- a/lib/sqlalchemy/engine/url.py
+++ b/lib/sqlalchemy/engine/url.py
@@ -641,7 +641,7 @@ class URL(NamedTuple):
         if self.port is not None:
             s += ":" + str(self.port)
         if self.database is not None:
-            s += "/" + self.database
+            s += "/" + quote_plus(self.database)
         if self.query:
             keys = list(self.query)
             keys.sort()
@@ -888,11 +888,10 @@ def _parse_url(name: str) -> URL:
             query = None
         components["query"] = query
 
-        if components["username"] is not None:
-            components["username"] = unquote(components["username"])
+        for comp in "username", "password", "database":
+            if components[comp] is not None:
+                components[comp] = unquote(components[comp])
 
-        if components["password"] is not None:
-            components["password"] = unquote(components["password"])
 
         ipv4host = components.pop("ipv4host")
         ipv6host = components.pop("ipv6host")

from sqlalchemy.

AlexeyDmitriev avatar AlexeyDmitriev commented on May 26, 2024

@zzzeek

I tried to understand whether I needed to escape my path when building an URL as a string (we don't have any strange character in the path to database but I wanted to fix it just in case). I've found that I can use URL class.
But while I was playing with it, I've noticed that behaviour is not what I expected

So, this behaviour doesn't bother me, I've already solved my problem, just decided to report what for me looks like a bug

from sqlalchemy.

CaselIT avatar CaselIT commented on May 26, 2024

I fear that the patch above will break existing use cases, since I'm not sure what all the various db driver would do in this case.

tried to create a db named "my?db=1" in pg and all kind of tools are failing to connect. Like I can't manage to connect using psql... Psycopg2 works though

from sqlalchemy.

zzzeek avatar zzzeek commented on May 26, 2024

this is less sensitive than "password". this breaks if someone had a database named "a%3Fb%3Dc" with URL escape symbols in it, that's basically it.

from sqlalchemy.

CaselIT avatar CaselIT commented on May 26, 2024

sure, probably not a big dial, but needs a breaking change node

from sqlalchemy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.